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

Re: NSUserDefaults


  • Subject: Re: NSUserDefaults
  • From: Andy Lee <email@hidden>
  • Date: Thu, 03 Sep 2009 17:13:10 -0400

On Sep 3, 2009, at 5:05 PM, Oftenwrong Soong wrote:
Why does NSUserDefaults provide method stringForKey but not a method setString:forKey (akin to setBool:forKey, setFloat:forKey, etc.)? This does not seem symmetric.

I'm using setObject:forKey when saving a NSString to the defaults database. Is this correct?

Yes. setObject:forKey: is for values that are objects -- not just NSString but NSNumber, NSDate, and the other classes mentioned in the method's documentation. Notice the other setXXX:forKey: methods take values that are not objects.


Going in the other direction, the reason there are stringForKey:, dateForKey:, etc. methods is that you might want to use stringForKey: (for example) even if you originally put an integer/date/float/etc. into the user defaults, or vice versa.

--Andy


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >NSUserDefaults (From: Oftenwrong Soong <email@hidden>)

  • Prev by Date: Re: NSControlTextDidChangeNotification - What key pressed?
  • Next by Date: Re: a bug in iphone SDK's creation of view based xib files.
  • Previous by thread: Re: NSUserDefaults
  • Next by thread: Re: NSUserDefaults
  • Index(es):
    • Date
    • Thread