- iOS 8.0+
MobilliumUserDefaults is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'MobilliumUserDefaults'
Set defaults(optional):
Defaults = UserDefaults.standard // or default is UserDefaults.standard
Create you DefaultsKey:
import MobilliumUserDefaults
extension DefaultsKey {
static let stringKey = Key<String>(key: "stringKey")
static let intKey = Key<Int>(key: "intKey")
static let boolKey = Key<Bool>(key: "boolKey")
static let doubleKey = Key<Double>(key: "doubleKey")
static let dateKey = Key<Date>(key: "dateKey")
static let arrayKey = Key<[String]>(key: "arrayKey")
}
Save value:
let value = "string"
DefaultsKey.stringKey.value = value
Get value:
let value = DefaultsKey.stringKey.value
Check value:
if DefaultsKey.stringKey.has {
//
}
Remove value:
DefaultsKey.stringKey.value = nil
//or
DefaultsKey.stringKey.remove()
Remove all values:
Defaults.removeAll()
MobilliumUserDefaults is available under the MIT license. See the LICENSE file for more info.