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

NSUserDefaults key validation


  • Subject: NSUserDefaults key validation
  • From: Dan Huntsinger <email@hidden>
  • Date: Fri, 16 Nov 2001 21:20:25 -0800

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


  • Follow-Ups:
    • Re: NSUserDefaults key validation
      • From: Peter Ammon <email@hidden>
    • Re: NSUserDefaults key validation
      • From: Kurt Revis <email@hidden>
    • Re: NSUserDefaults key validation
      • From: Mike Shields <email@hidden>
    • Re: NSUserDefaults key validation
      • From: Angela Brett <email@hidden>
  • Prev by Date: Re: Window load delegate function?
  • Next by Date: Re: scrolling an NSText to the bottom
  • Previous by thread: Re: NSImage leaks Help!
  • Next by thread: Re: NSUserDefaults key validation
  • Index(es):
    • Date
    • Thread