Re: Newb Question re NSUserDefaults and Ints
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