Skip to content
This repository has been archived by the owner on Nov 21, 2023. It is now read-only.

nashysolutions/Directory

Repository files navigation

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.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages