Re: Preferences using NSUserDefaults (newbie)
Re: Preferences using NSUserDefaults (newbie)
- Subject: Re: Preferences using NSUserDefaults (newbie)
- From: Carlos Weber <email@hidden>
- Date: Thu, 21 Jun 2001 11:54:12 -1000
On Thursday, June 21, 2001, at 12:10 , Jorge Salvador Caffarena wrote:
Hello,
I am adding preferences support to my application using NSUserDefaults.
I looked at the tutorial found in cocoadevcentral.com, but it do not
work in my app.
For example they say that you can use this to check if the preferences
file exists:
if (! [NSUserDefaults standardUserDefaults] )
{
// create the default preferences
}
But the condition never evaluates to false, even if there are no
preferences file (a plist I suppose).
Also they show some code to initialize the preferences for the first
time, and they use this:
// create a dictionary
NSMutableDictionary *defaultPrefs = [NSMutableDictionary dictionary];
// put default prefs in the dictionary
[defaultPrefs setBool: YES forKey: somePrefOnOrOff];
// register the dictionary of defaults
[preferences registerDefaults: defaultPrefs];
NSLog(@"Registered defaults: %@", defaultValues);
But the compiler complaints here and says that "NSMutableDictionary do
not respond to setBool:forKey message".
I think this example code is incorrect. Check out the documentation for
the NSUserDefaults class; no "description forthcoming", it's actually
informative. Then check out the UserDefaults example at
/Developer/Examples/AppKit/UserDefaults on your hard disk.