Directory

3.0.0

A means of accessing the file system conveniently in a SwiftUI environment.
nashysolutions/Directory

What's New

Release 3.0.0

2021-09-21T06:32:26Z

See Changelog.

Directory

A means of accessing the file system in a SwiftUI environment, conveniently.

Usage

Let's assume you have a data type called 'Project'.

struct Project: Codable {
    let name: String
}

Using this package, you could setup a @StateObject of type Directory<Project> which will store that type to disk. You may also want to save images using PhotosDirectory<Project>.

struct ContentView: View {
    
    @StateObject var store: Directory<Project>
    
    var body: some View {
        List {
            ForEach(store.fetchedItems) { project in
                // do something
            }
        }
        .onAppear(perform: {
            store.fetch(.async(.global(qos: .userInitiated)))
        })
    }
        
    private func addProject() {
        let project = Project(name: "Project " + UUID().uuidString)
        try! store.append(project)
    }
}

For the above to compile, the type Project would need to conform to a few protocols. For a detailed implementation, see the wiki.

Demo App available here.

Installation

Use the Swift Package Manager documentation. See the wiki for more details.

Description

  • Swift Tools 5.4.0
View More Packages from this Author

Dependencies

Last updated: Sun Oct 17 2021 05:11:48 GMT-0500 (GMT-05:00)