• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Userdefaults, their initial values, and bindings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Userdefaults, their initial values, and bindings (From: Francis Derive <email@hidden>)
 >Re: Userdefaults, their initial values, and bindings (From: mmalc crawford <email@hidden>)
 >Re: Userdefaults, their initial values, and bindings (From: Francis Derive <email@hidden>)

  • Prev by Date: Re: Userdefaults, their initial values, and bindings
  • Next by Date: Re: Mysterious crash in loaded nib
  • Previous by thread: Re: Userdefaults, their initial values, and bindings
  • Next by thread: Mysterious crash in loaded nib
  • Index(es):
    • Date
    • Thread