用于访问 Keychain 的 Swift 5 框架
Swift 版本 | 最新版本 |
---|---|
4.1 | 3.0.4 |
5.0 | 3.1.0 |
KeychainStore<T: Codable>
是一个泛型类,用于存储符合 Codable
协议的类的实例
let store = KeychainStore<Card>(account: "test")
let card = Card(number: "4111111111111111", name: "Me")
// save card:
try store.set(object: card, forKey: "my card")
// or:
try store.set(object: card, forKey: "my card", accessibility: .whenPasscodeSetThisDeviceOnly)
// get card
let card = try store.object(forKey: "my card")
此外,KeychainStringStore
类可以将 String
实例保存在 Keychain 中。