Forever

持久化任何 Codable 值。

如需完整文档,请点击此处

@Forever("todos") var todos = [Todo(title: "Feed the cat", isCompleted: true),
                               Todo(title: "Play with cat"),
                               Todo(title: "Get allergies"),
                               Todo(title: "Run away from cat"),
                               Todo(title: "Get a new cat")]
struct Todo: Codable {
    var title: String
    var isCompleted = false
}

一行代码即可持久化 @Forever

@Forever("counter") var counter = 1

使用 UIKit? Forever+Combine

感谢 #1

class ViewController: UIViewController {

    @Forever("counter") var counter = 1
    var cancellables = Set<AnyCancellable>()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        _counter.publisher.sink(receiveValue: { value in
            print(value)
        })
        .store(in: &cancellables)
    }
    //...
}

不喜欢 Forever? 使用其他的。

@DontDie("name") var name = "Potato"
@DontLeaveMe("todo") var todo = Todo(...)
@BePersistent("a") var b = true

安装

要求

平台 版本
iOS 13.0 或更高版本
macOS 11.0 或更高版本
watchOS 6.0 或更高版本
tvOS 13.0 或更高版本

添加为 Swift Package

在 Xcode 中,文件 → 添加包… → 在搜索字段中粘贴 https://github.com/jiachenyee/forever