Re: NSUserDefaults and objects
Re: NSUserDefaults and objects
- Subject: Re: NSUserDefaults and objects
- From: Chris Parker <email@hidden>
- Date: Mon, 13 Mar 2006 10:02:17 -0800
On Mar 13, 2006, at 8:08 AM, Alan Smith wrote:
Okay. Yes, sorry, there was a question there.
How do I load a pref file that's not in the pref folder?
In order to do something like this, you're going to take advantage of
NSUserDefaults' registration domain.
Quoth the docs at http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ObjC_classic/Classes/NSUserDefaults.html
:
"registerDefaults:
Adds the specified defaults to the NSRegistrationDomain — a cache of
application-provided defaults that are used unless a user overrides
them."
It takes an NSDictionary as its argument.
If you generate a plist (either programmatically or via Property List
Editor), you can write it out to disk. If you make the plist file part
of your Xcode project it should get copied into your main bundle's
resources folder automatically (that's <yourapp>.app/Contents/
Resources). Let's call that file "StartingValuesForDefaults.plist".
Now, you can determine that path with the NSBundle -
pathForResource:ofType: API:
NSString * pathToPlist = [[NSBundle mainBundle]
pathForResource:@"StartingValuesForDefaults" ofType:@"plist"];
NSDictionary * values = [NSDictionary
dictionaryWithContentsOfFile:pathToPlist];
[[NSUserDefaults standardUserDefaults] registerDefaults:values];
(warning: the above code is typed into Mail.app, and compiled there,
too. :) ).
Now, if the user ever sets other values for the key/value pairs that
appear in the registration domain, those values are used. If they
clear their own values out the user will get the ones you specified in
the plist.
.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