Re: Userdefaults, their initial values, and bindings
Re: Userdefaults, their initial values, and bindings
- Subject: Re: Userdefaults, their initial values, and bindings
- From: mmalc crawford <email@hidden>
- Date: Mon, 20 Aug 2007 09:59:15 -0700
On Aug 20, 2007, at 8:47 AM, Francis Derive wrote:
Sorry, I couldn't understand the preceding.
So, how could I do to have these defaults values created in a plist
in the application bundle, rather than in the home library ? Does it
make sense to do that or should I go on with the plist in the
Library ?
The *user's* defaults are stored in ~/Library/Preferences.
The idea behind putting the *application* defaults in a file in the
app bundle is that you can then modify these independently of the
code. Rather than writing code like:
NSMutableDictionary *appDefaults = [NSMutableDictionary dictionary];
[appDefaults setObject:@"YES" forKey:@"DeleteBackup"];
[appDefaults setObject:@"First" forKey:@"FirstName"];
[appDefaults setObject:@"Last" forKey:@"LastName"];
/*
etc.
*/
[[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
NSString *userDefaultsValuesPath =
[[NSBundle mainBundle] pathForResource:@"UserDefaults"
ofType:@"plist"];
NSDictionary *userDefaultsValuesDict =
[NSDictionary dictionaryWithContentsOfFile:userDefaultsValuesPath];
[[NSUserDefaults standardUserDefaults]
registerDefaults:userDefaultsValuesDict];
Some people fid it easier or more convenient to work with a plist file
directly than to maintain the defaults code -- especially if different
classes register defaults.
mmalc
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden