A single value proxy for NSUserDefaults, with clean API.
With OneStore…
- Create one proxy(an
OneStore
object) for each NSUserDefaults value. - Multiple NSUserDefaults and namespaces are supported with
Stacks
.
Basic
let name = OneStore<String>("name")
let age = OneStore<Int>("age")
name.value = "muukii"
age.value = 18
Specify Stack
let stack = Stack(userDefaults: NSUserDefaults(suiteName: "group.me.muukii.Fil")!, namespace: "me")
let name = OneStore<String>("name", stack: stack)
let age = OneStore<Int>("age", stack: stack)
name.value = "muukii"
age.value = 18
Remove object
let name = OneStore<String>("name", stack: stack)
name.value = nil
Remove all objects on namespace
let stack = Stack(userDefaults: NSUserDefaults.standardUserDefaults(), namespace: "me")
let name = OneStore<String>("name", stack: stack)
stack.removeAllObjectsOnNamespace()
/* or */
name.stack.removeAllObjectsOnNamespace()
Realworld example
enum Me {
static let name = OneStore<String>("name", stack: Me.stack)
static let age = OneStore<Int>("age", stack: Me.stack)
private static let stack = Stack(userDefaults: NSUserDefaults.standardUserDefaults(), namespace: "me")
}
Me.name.value = "muukii"
Swift 3.0
OneStore is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "OneStore"
muukii, m@muukii.me
OneStore is available under the MIT license. See the LICENSE file for more info.