Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

davidmirv

macrumors newbie
Original poster
Apr 9, 2013
6
0
I am not understanding when I change 2 values an NSTextField and a NSTextView via
Code:
_stopwatchLabel setStringValue:@"00:00:00"];
[taskDescription setString:@""];

which both have their values bound to Userdefaultscontroller , when I trigger that code and quit the app the new values aren't saved..and the old values are restored..
I did some tinkering around and subscribed to NSUserDefaultsDidChangeNotification and noticed that when I set those values its not even triggering the notification? Have also tried syncronize on the nsuserdefaults within nsuserdefaultscotnroller to no avail (setAppliesImediately is true so a save: would not help)

Do I have to also update NSUserDefaults manually when setting values manually??

can anyone help me out? Not sure why I have this seemingly strange NSUserDefaults behavior

thanks
 

onejed1

macrumors newbie
Jun 15, 2007
26
1
I use [NSUserDefaults standardUserDefaults] a lot, and add/change stuff manually. You have to synchronize after you manually add/change things so that your changes are "committed"...

e.g. in my case:
Code:
[[NSUserDefaults standardUserDefaults] synchronize];

So it's probably similar in your case.
 

Catfish_Man

macrumors 68030
Sep 13, 2001
2,579
2
Portland, OR
I use [NSUserDefaults standardUserDefaults] a lot, and add/change stuff manually. You have to synchronize after you manually add/change things so that your changes are "committed"...

e.g. in my case:
Code:
[[NSUserDefaults standardUserDefaults] synchronize];

So it's probably similar in your case.

You absolutely should not need to call -synchronize during normal usage of NSUserDefaults on any recent version of Mac OS X. If you've run across a case where you do need to, please file a bug at bugreport.apple.com
 

onejed1

macrumors newbie
Jun 15, 2007
26
1
You absolutely should not need to call -synchronize during normal usage of NSUserDefaults on any recent version of Mac OS X. If you've run across a case where you do need to, please file a bug at bugreport.apple.com

Sorry, i'm speaking from an iOS developer perspective, I haven't had the chance to try out Mac OS development and was unaware of this distinction. Thanks for pointing that out.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.