KeyValueData
用于存储 Key-Value 型数据的 Utility。可根据不同的需求使用不同的后端存储。
通过相同的协议管理不同后端的关键值数据。
示例
// Load/Create data
var _dataInKeyChain: KeyValueData = KeyValueDictionaryInKeychain(withKey: "account")
var _dataInUserDefaults: KeyValueData = KeyValueDictionaryInUserDefaults(withKey: "account")
// Data in => NSHomeDirectory()+"/Documents/\(withKey).plist"
var _dataInPlist: KeyValueData = KeyValueDictionaryInDocumentsPlist(withKey: "account")
// Data in => NSHomeDirectory()+"/Documents/KeyValue.sqlite", table: withKey
var _dataInSQLite: KeyValueData = KeyValueDictionaryInSqlite(withKey: "account")
// Data in iCloud KV storage with key: withKey
var _dataIniCloud: KeyValueData = KeyValueDictionaryIniCloud(withKey: "account")
// set/get data from KV
_data["accountid"] = "12345678"
let id = _data["accountid"] as! String
// write data to disk
// this is not necessary for KeyChain/SQLite
_data.sync()
需求
- iOS 14.0+
安装
可以通过 CocoaPods 安装:
KeyValueData 通过 CocoaPods 提供。要安装它,请在 Podfile 中添加以下行:
pod "KeyValueData"
作者
许可证
KeyValueData 在MIT许可证下可用。更多信息请查看LICENSE文件。