Re: NSUserDefaultsController
Re: NSUserDefaultsController
- Subject: Re: NSUserDefaultsController
- From: mmalcolm crawford <email@hidden>
- Date: Sun, 9 Nov 2003 01:07:40 -0800
On Nov 8, 2003, at 8:03 PM, James Spencer wrote:
NSString * server = [[[NSUserDefaultsController
sharedUserDefaultsController]
defaults] stringForKey:@"smtpServer"];
Thank you very much for this as it allows me to ask a more intelligent
question, or at least I hope its more intelligent. This is what I
initially tried. Unfortunately, what is being returned in server is
nil.
It turns out things are a little less straightforward (and thanks to
Scott for helping to clear this up).
If you have *saved* *new* defaults, then you can retrieve then from
standard user defaults.
*Initial settings*, though, are *not* saved into the registration
domain.
Given:
[[NSUserDefaultsController sharedUserDefaultsController]
setInitialValues:
[NSDictionary dictionaryWithObject:@"smtp.mac.com"
forKey:@"smtpServer"]];
and no other changes to user defaults:
NSLog(@"NSUserDefaultsController: %@", [[[NSUserDefaultsController
sharedUserDefaultsController] values] valueForKey:@"smtpServer"]);
NSLog(@"NSUserDefaults: %@", [[NSUserDefaults standardUserDefaults]
stringForKey:@"smtpServer"]);
returns
NSUserDefaultsController: smtp.mac.com
NSUserDefaults: (null)
If you now make a change and save, you get
NSUserDefaultsController: smtp.myisp.com
NSUserDefaults: smtp.myisp.com
If you revert to initial settings, you get back to
NSUserDefaultsController: smtp.mac.com
NSUserDefaults: (null)
See:
<
http://homepage.mac.com/mmalc/CocoaExamples/SimplePreferences.zip>
So, if you are using the user defaults controller and you want to be
able to retrieve initial settings (which is likely to be the case...),
you should use
[[[NSUserDefaultsController sharedUserDefaultsController] values]
The documentation does not currently make this clear. Moreover it's
not clear if this is really the behaviour that most would expect
(personally, and speaking personally, I expected initial values to be
stored automatically in the registration domain and accessible from
standardUserDefaults...)? I'd be interested in others' views on this.
mmalc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.