• 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: Help with NSDictionary!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with NSDictionary!


  • Subject: Re: Help with NSDictionary!
  • From: Chris Hanson <email@hidden>
  • Date: Sun, 28 Jul 2002 20:30:21 -0500

First of all, you really don't want to use this sort of mechanism for storing your application's preferences. Instead, you want to use NSUserDefaults. If you need finer-grained control of your application's preferences, you want to use CFPreferences, which operates on the same preferences database.

Secondly, this line of code:

if ([prefs objectForKey:@"FirstLaunch"]==@"YES") {

is your problem. You're comparing the pointer returned from the expression [prefs objectForKey:@"FirstLaunch"] with the pointer to the constant NSString @"YES". Even if the objects are equal the pointers may not be. You want to use isEqualTo: or isEqualToString: instead of "==". Just as in ANSI C you never want to use "==" for string comparison.

Once your code is using NSUserDefaults like a proper Cocoa citizen, you can just check to see if a particular key exists and if it doesn't use that to indicate to your application is being launched for the first time. Then just set the key in your defaults and synchronize them.

-- Chris

--
Chris Hanson | Email: email@hidden
bDistributed.com, Inc. | Phone: +1-847-372-3955
Making Business Distributed | Fax: +1-847-589-3738
http://bdistributed.com/ | Personal Email: email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Help with NSDictionary! (From: Albert Atkinson <email@hidden>)

  • Prev by Date: Re: Serial number verification / obfuscation
  • Next by Date: NSUserDefaults, an array, and SIGBUS 10
  • Previous by thread: Re: Help with NSDictionary!
  • Next by thread: Re: Help with NSDictionary!
  • Index(es):
    • Date
    • Thread