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 protected])
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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]