• 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: NSUserDefaults key validation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSUserDefaults key validation


  • Subject: Re: NSUserDefaults key validation
  • From: Peter Ammon <email@hidden>
  • Date: Sat, 17 Nov 2001 17:30:08 -0500

On Saturday, November 17, 2001, at 12:20 AM, Dan Huntsinger wrote:

Hi all,

I have a routine that reads in my prefs, and I've got a bug in it. The
following code is an example of what I'm doing:

// load preferences
prefs = [NSUserDefaults standardUserDefaults];

// get show hints pref
// if no prefs have been set, set to default
if( [prefs boolForKey:@"ShowHintMessages"] != nil )
showHints = [prefs boolForKey:@"ShowHintMessages"];
else
showHints = NO;

My problem is this: since the key in this case is a BOOL, if it is set to
NO, then it will be interpreted as being nil. What I really need is a
method to check if a given key is valid(exists), but I don't see any such
method in the definition of NSUserDefualts. Does anyone have a suggestion
or a method they have used in this situation?

Thanks,
Dan

I usually try to set it up so that the default value of nil is the proper default value for the preference in my app. Barring that, use objectForKey rather than boolForKey and check if the returned object is nil.

-Peter


References: 
 >NSUserDefaults key validation (From: Dan Huntsinger <email@hidden>)

  • Prev by Date: Re: [OT] Standard OS X Compression format
  • Next by Date: Re: C/C++/Java development
  • Previous by thread: Re: NSUserDefaults key validation
  • Next by thread: &xxx; thingies
  • Index(es):
    • Date
    • Thread