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

Preferences using NSUserDefaults (newbie)


  • Subject: Preferences using NSUserDefaults (newbie)
  • From: Jorge Salvador Caffarena <email@hidden>
  • Date: Thu, 21 Jun 2001 12:10:02 +0200

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".

So now I am really messed up, because this seems a easy and quick way of implementing preferences, but I am unable to get it to work.

Thanks in advance,

Jorge Salvador Caffarena
http://homepage.mac.com/eevyl/


  • Follow-Ups:
    • Re: Preferences using NSUserDefaults (newbie)
      • From: Carlos Weber <email@hidden>
    • Re: Preferences using NSUserDefaults (newbie)
      • From: Eric Peyton <email@hidden>
    • Re: Preferences using NSUserDefaults (newbie)
      • From: Matt Ridley <email@hidden>
  • Prev by Date: Filling arguments for AuthorizationExecuteWithPrivileges (very newbie)
  • Next by Date: Re: WWDC Dev Tools / Software update
  • Previous by thread: Re: Filling arguments for AuthorizationExecuteWithPrivileges (very newbie)
  • Next by thread: Re: Preferences using NSUserDefaults (newbie)
  • Index(es):
    • Date
    • Thread