• 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: Preferences using NSUserDefaults (newbie)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


References: 
 >Preferences using NSUserDefaults (newbie) (From: Jorge Salvador Caffarena <email@hidden>)

  • Prev by Date: First questions
  • Next by Date: Validating visible Toolbar items
  • Previous by thread: Re: Preferences using NSUserDefaults (newbie)
  • Next by thread: A few basic questions
  • Index(es):
    • Date
    • Thread