• 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: Another user defaults question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Another user defaults question


  • Subject: Re: Another user defaults question
  • From: Uli Kusterer <email@hidden>
  • Date: Fri, 25 Aug 2006 15:37:08 +0200

Am 25.08.2006 um 01:19 schrieb Bill Bumgarner:
You would use the NSValue class (Subclass, typically) to encapsulate the values.

In particular NSNumber, for most of the types you mentioned.

However, there is a much better way to do this:

Add a "RegistrationDefaults" key to your application's Info.plist. Make the value a dictionary that contains the set of registration defaults that you want to use. I.e. an entry like (you'll need to convert this to the XML form of plists):

{
... info plist content here ....
RegistrationDefaults = {
	NeutralColor = "whiteColor";
	PositiveThreshold = 10.0;
	DisplayInMenuBar = NO;
	IndexNumberFormat = "###,##0.00";
};
}

And then, somewhere very early in your app's execution:

[[NSUserDefaults standardUserDefaults] registerDefaults:
[[[NSBundle mainBundle] infoDictionary] objectForKey: @"RegistrationDefaults"]];

I personally prefer not to litter into Apple's Info.plist. The Finder and other system stuff reads this file, so if I happen to choose a name that Apple suddenly decides to claim, my app might break. I usually create a .plist file using Property List Editor and add that to my app's resources, then load it using code like (typed in Mail):


NSString* fpath = [[NSBundle mainBundle] pathForResource: @"DefaultPrefs"
ofType: @"plist"];
NSDictionary* defaultDefaults = [NSDictionary dictionaryWithContentsOfFile: fpath];
[[NSUserDefaults standardUserDefaults] registerDefaults: defaultDefaults];


Cheers,
-- M. Uli Kusterer
http://www.zathras.de


_______________________________________________ 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
  • Follow-Ups:
    • Re: Another user defaults question
      • From: Ivan Kourtev <email@hidden>
References: 
 >Another user defaults question (From: Ivan Kourtev <email@hidden>)
 >Re: Another user defaults question (From: Bill Bumgarner <email@hidden>)

  • Prev by Date: Re: NSDatePickerCell -- Ever Worked ??
  • Next by Date: Re: dataFromFile
  • Previous by thread: Re: Another user defaults question
  • Next by thread: Re: Another user defaults question
  • Index(es):
    • Date
    • Thread