• 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: Newb Question re NSUserDefaults and Ints
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newb Question re NSUserDefaults and Ints


  • Subject: Re: Newb Question re NSUserDefaults and Ints
  • From: "Michael Ash" <email@hidden>
  • Date: Sat, 30 Aug 2008 18:03:55 -0400

On Sat, Aug 30, 2008 at 4:35 PM, Brad Gibbs <email@hidden> wrote:
> While I did learn some things from this, I'm confused about NSUserDefaults
> and the values it can store.  I created an NSMutableDictionary to register
> the defaults, which is, I believe archived as a property list.  Floats can
> be associated with NSString keys and stored in dictionaries, and there are
> methods for floatForKey: and setFloat: forKey: so, storing floats in a
> dictionary is supported, but, according to my understanding of Apple's
> documentation, I can't archive floats in a property list.  I thought that I
> needed to transform the float into an NSNumber before saving to
> NSUserDefaults, and then transform the NSNumber to a float before I could
> use it to set the gradient angle.

Those two methods are simple conveniences for you. In reality they
just convert to and from NSNumber without forcing you to do it:

- (float)floatForKey:(NSString *)k { return [[self objectForKey:k]
floatValue]; }
- (void)setFloat:(float)f forKey:(NSString *)k { [self
setObject:[NSNumber numberWithFloat:f] forKey:k]; }

That's all, nothing weird or contradictory, just a little bit of a
shortcut provided for you.

Mike
_______________________________________________

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: 
 >Newb Question re NSUserDefaults and Ints (From: Brad Gibbs <email@hidden>)
 >Re: Newb Question re NSUserDefaults and Ints (From: Graham Cox <email@hidden>)
 >Re: Newb Question re NSUserDefaults and Ints (From: Graham Cox <email@hidden>)
 >Re: Newb Question re NSUserDefaults and Ints (From: Brad Gibbs <email@hidden>)

  • Prev by Date: NSTableView "sometimes" doesn't repaint on reloadData:?
  • Next by Date: Re: NSTableView "sometimes" doesn't repaint on reloadData:?
  • Previous by thread: Re: Newb Question re NSUserDefaults and Ints
  • Next by thread: Cancel application terminate on Logout/Shut Down
  • Index(es):
    • Date
    • Thread