Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 13, 2013, 03:17 PM   #1
davidmirv
macrumors newbie
 
Join Date: Apr 2013
NSUserDefaults(Controller)

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
davidmirv is offline   0 Reply With Quote
Old Apr 15, 2013, 12:30 PM   #2
onejed1
macrumors newbie
 
Join Date: Jun 2007
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.
onejed1 is offline   0 Reply With Quote
Old Apr 15, 2013, 06:21 PM   #3
Catfish_Man
macrumors 68030
 
Catfish_Man's Avatar
 
Join Date: Sep 2001
Location: Portland, OR
Send a message via AIM to Catfish_Man
Quote:
Originally Posted by onejed1 View Post
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
Catfish_Man is offline   0 Reply With Quote
Old Apr 17, 2013, 03:29 PM   #4
onejed1
macrumors newbie
 
Join Date: Jun 2007
Quote:
Originally Posted by Catfish_Man View Post
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.
onejed1 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
textfield value not getting saved to nsuserdefaults abcdefg12345 Mac Programming 5 May 8, 2014 06:43 PM
About push view controller into a navigation controller stack. cthesky iPhone/iPad Programming 5 Nov 9, 2012 08:36 AM
Segue from Normal View controller to navigation controller daproject85 iPhone/iPad Programming 0 Sep 29, 2012 03:26 PM
NSCoding/NSUserDefaults nashyo iPhone/iPad Programming 5 Jun 25, 2012 05:41 AM
push to a specific view controller regardless of which controller is active johnmerlino iPhone/iPad Programming 2 Jun 19, 2012 02:24 PM

Forum Jump

All times are GMT -5. The time now is 03:44 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC