A type safe swift ResultBuilder DSL for structured directories
0

Configure Feed

Select the types of activity you want to include in your feed.

8 3 0

Clone this repository

https://git.vm.fail/woody.fm/swift-file-tree https://git.vm.fail/did:plc:jlwrolmjzsveohsjbmadixnp
ssh://git@knot1.tangled.sh:2222/woody.fm/swift-file-tree ssh://git@knot1.tangled.sh:2222/did:plc:jlwrolmjzsveohsjbmadixnp

For self-hosted knots, clone URLs may differ based on your setup.


README.md

FileTree#

FileTree is a Swift package that provides a type-safe, declarative way to interact with file system structures.

Features#

  • Declarative file system structure definition
  • Type-safe read and write operations to a directory of that structure
  • Render that same struture to a SwiftUI sidebar

Installation#

Add the following to your Package.swift file:

dependencies: [
    .package(url: "https://github.com/woodymelling/swift-file-tree", from: "0.1.0")
]

Usage#

import FileTree
import UniformTypeIdentifiers

let blogFileTree = FileTree {
    Directory("Blog") {
        File("About", .txt)
        Directory("Posts") {
            File.Many(withExtension: .md)
        }
    }
}

From here, you can:

  • Read and write raw data from the file system, allowing you to load Markdown posts, images, configurations, or any binary content.
  • Convert raw data into well-defined Swift types to ensure your application logic remains clean and type-safe. Transform text files into strings, decode JSON into models, or parse custom formats into domain-specific types.
  • Render file trees in SwiftUI using FileTreeViewable for a visual representation of your project’s structure. Easily inspect directories and files right in your app’s UI.

This approach lets you keep your file system logic expressive yet separated from your business logic. You decide how much detail to expose to the rest of your application, and Swift File Tree takes care of bridging the gap between your on-disk data and in-memory models.

Essentials#

  • Getting Started Learn the basics of defining a file tree and interacting with it.

Contributing#

As this is a work in progress, contributions are welcome! Please open an issue to discuss proposed changes before submitting a pull request.