There's only three steps to set up SwiftyUserDefaultsStore:
Step 1: Define user Defaults keys.
let usernameKey = StoreKey<String>(key: "username")
let userIdKey = StoreKey<Int>(key: "userId")
Step 2: Use keys to get user defaults value
// Getting user defaults value
let username = usernameKey.value
// Setting user defaults value
usernameKey.value = newValue
var userId: Int {
get {
return userIdKey.value ?? 0
}
set {
userIdKey.value = newValue
}
}
Step 3: Use it wherever you want🎉
if userId != 0 {
label.text = username
}
userId = response.userId
SwiftyUserDefaultsStore currently supports limited types, like String, Int, Bool. It would be appreciated to recieve pull requests adding more types🙇
- Insert
github "yuzushioh/SwiftyUserDefaultsStore"
to your Cartfile. - Run carthage update.
- Copy
Sources
to your Xcode project.
Absolutely!
SwiftyUserDefaultsStore is available under the MIT license. See LICENSE.txt for details.