目录
目录README.md

Directory

iOS macOS

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, Equatable, Container {

    let name: String
    
    // See wiki/typical-implementation
}

By conforming to the above protocols, you may now create Directory<Project> or 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.fetchAndWait()
            Task {
               await store.fetch()
            }
        })
    }
        
    // stores permanently to disk
    // triggers UI re-render
    private func addProject() {
        let project = Project(name: "Project " + UUID().uuidString)
        try! store.append(project)
        // See wiki/useful-api for additional functionality.
    }
}
  • For parent-child folder relationships see wiki.
  • Demo App available here.
  • Only suitable for small payloads. If using larger files and / or CloudKit consider using NSFilCoordinator directly.

Installation

Use the Swift Package Manager documentation.

关于
361.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号