Re: A problem of NSUserdefaults
Re: A problem of NSUserdefaults
- Subject: Re: A problem of NSUserdefaults
- From: Chris Parker <email@hidden>
- Date: Thu, 13 Jul 2006 10:05:13 -0700
Hello,
On Jul 13, 2006, at 9:48 AM, Bus Mini wrote:
- (id)init
{
[super init];
NSMutableDictionary * defaultPrefs = [NSMutableDictionary
dictionary];
[defaultPrefs setObject:@"Learning Cocoa"
forKey:@"FavBook"];
[defaultPrefs setObject:@"San Francisco"
forKey:@"FavCity"];
[defaultPrefs setObject:@"Red"
forKey:@"FavColor"];
[defaultPrefs setObject:@"Mexican" forKey:@"FavFood"];
prefs = [[NSUserDefaults standardUserDefaults]
retain];
[prefs
registerDefaults:defaultPrefs];
return self;
}
Your call to [prefs registerDefaults:defaultPrefs]; installs the key/
value pairs in the registration domain, which is volatile (i.e. not
saved to disk). It's a "fallback" domain in the search list which you
can use to place your application's default values.
Calling -synchronize does not write these values out.
If you were to do something like this later in your code:
NSUserDefaults * defs = [NSUserDefaults standardUserDefaults];
[defs setObject:@"New York" forKey:@"FavCity"];
[defs synchronize];
Then the only key/value pair written to your application's preferences
would be the FavCity/New York pair.
The conceptual docs on NSUserDefaults are here:
http://developer.apple.com/documentation/Cocoa/Conceptual/UserDefaults/index.html
And you can get to the class reference from that page as well.
.chris
--
Chris Parker
Cocoa Frameworks
Apple Computer, Inc.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden