CocoaPods trunk is moving to be read-only. Read more on the blog, there are 13 months to go.
| TestsTested | ✓ |
| LangLanguage | SwiftSwift |
| License | MIT |
| ReleasedLast Release | Feb 2017 |
| SwiftSwift Version | 3.0 |
| SPMSupports SPM | ✓ |
Maintained by Max Sokolov.
Kee is a simple key-value persistance library written in Swift with type-safety in mind. It allows you to store primitives like Int or String and any complex objects which can be represented as a key-value Dictionary.
Int, String, etc.), Arrays and Dictionarieslet storage = KeyValueStorageFactory().defaultsStorage()
let myValue: Float = 42.0
try? storage.setValue(myValue, forKey: "myKey")let storage = KeyValueStorageFactory().defaultsStorage()
let myValue: Float? = storage.getValue(forKey: "myKey")Or using try/catch
let storage = KeyValueStorageFactory().defaultsStorage()
do {
let myValue: Float = try storage.getValue(forKey: "myKey")
} catch let error {
// handle error if needed
}Let’s say you have a custom User object that you want to persist
struct User {
let username: String
}You have to conform to the KeyValueRepresentable to allow object to be archived
extension User: KeyValueRepresentable {
var keyValueRepresentation: KeyValueRepresentation {
return [
"username": username
]
}
init(keyValueRepresentation rep: KeyValueRepresentation) throws {
username = rep["username"] as? String ?? ""
}
}let storage = KeyValueStorageFactory().defaultsStorage()
let user = User(username: "John Doe")
try? storage.setObject(user, forKey: "user")let storage = KeyValueStorageFactory().defaultsStorage()
let user: User? = storage.getObject(forKey: "user")Clone the repo and drag files from Sources folder into your Xcode project.
Kee is available under the MIT license. See LICENSE for details.