Re: NSUserDefaults question
Re: NSUserDefaults question
- Subject: Re: NSUserDefaults question
- From: John Anderson <email@hidden>
- Date: Thu, 6 Jun 2002 17:22:54 -0700
I think what you want to use here is standardUserDefaults. Make sure you have an identifier set in your bundle settings. You'll typically want to initialize your defaults in the main() function of your application, before any classes get loaded. For example, this is the main() function of my application (Presence):
int main(int argc, const char *argv[])
{
NSMutableDictionary *defaultSettings;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
defaultSettings = [NSMutableDictionary dictionary];
[defaultSettings setObject:@"127.0.0.1" forKey:@"defaultServer"];
[defaultSettings setObject:@"default" forKey:@"defaultUsername"];
[defaultSettings setObject:[NSNumber numberWithInt:15550] forKey:@"defaultServerPort"];
[defaultSettings setObject:[NSNumber numberWithBool:YES] forKey:@"startServerAtStartup"];
[defaultSettings setObject:@"" forKey:@"previousVersion"];
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultSettings];
[pool release];
return NSApplicationMain(argc, argv);
}
This way you initialize with standard defaults, and if none of them get changed then you're not wasting space with another prefs file.
Access the prefs by using [NSUserDefaults standardDefaults] and sending it messages as detailed in the documentation for the NSUserDefaults class.
John Anderson
On Thursday, June 6, 2002, at 04:49 PM, Hisaoki Nishida wrote:
Hi,
I have a quick question on NSUserDefaults.
When I load user preferences using NSUserDafaults, I want it to be accessible to a few classes in my program, not just one class. The classes would need to get information from the prefs to initialize themselves. What would be the best way to use NSUserDefaults here?
Thanks,
-Hisaoki N.
_______________________________________________
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.
_______________________________________________
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.