NSUserDefaults Bindings Reset
NSUserDefaults Bindings Reset
- Subject: NSUserDefaults Bindings Reset
- From: Michael de Haan <email@hidden>
- Date: Sun, 01 Nov 2015 04:58:57 -0800
I have made a test Project to understand resetting UserDefaults.
A label’s value is bound to the shared UserDefaults in the UI, and works as expected when the Defaults are updated
@IBAction fun changeMeaningOfLife………………...
let meaning = Int(arc4random() % 99)
NSUserDefaults.standardUserDefaults().setInteger(meaning, forKey: "TestKey")
Now, to reset to the default value, the code below does work, but the UI is not immediately updated. i.e. a restart of the app is needed.
@IBAction func resetToDefault(sender: AnyObject) {
let bundleIdentifier = NSBundle.mainBundle().bundleIdentifier
let mol = NSUserDefaults.standardUserDefaults().stringForKey("TestKey")
NSUserDefaults.standardUserDefaults().removePersistentDomainForName(bundleIdentifier!)
}
If I add the line of code…… (—>>>>) below
@IBAction func resetToDefault(sender…..
………………..
let mol = NSUserDefaults.standardUserDefaults().stringForKey("TestKey")
———>>>>> NSUserDefaults.standardUserDefaults().setInteger(42, forKey: "TestKey")
The change is immediately reflected in the UI.
Could anyone help me understand why the bindings seem to miss the changes if only "removePersistentDomainForName(bundleIdentifier!)” is called?
Thanks
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden