A means of accessing the file system in a SwiftUI environment, conveniently.
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.
Use the Swift Package Manager documentation. See the wiki for more details.