Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newb Question re NSUserDefaults and Ints




On 30 Aug 2008, at 11:54 am, Brad Gibbs wrote:

NSLog(@"gradient angle is %d", [elementBarGradientAngleTextField intValue]);
[defaults setInteger:[elementBarGradientAngleTextField intValue] forKey:ICNElementBarGradientAngleKey];
NSLog(@"Element bar angle is now: %d", [ICNElementBarGradientAngleKey intValue]);
}


I get:

2008-08-29 18:42:10.627 Icon[35645:10b] gradient angle is 75
2008-08-29 18:42:10.628 Icon[35645:10b] Element bar angle is now: 0

Hmm, yes. Well, what is your code doing? It's first taking the intValue from elementBarGradientAngleTextField. It then sets that value in the user defaults, quite correctly, using the key "ICNElementBarGradientAngleKey" which I take it is defined somewhere as a constant literal string. You then ask the KEY for its intValue. The key's intValue is indeed 0, because the key is "ICNElementBarGradientAngleKey" which isn't a number.


I think you mean:

NSLog(@"Element bar angle is now: %d", [defaults integerForKey:ICNElementBarGradientAngleKey]);

which should return the same as the first log.


meant to be used with an int, or an object, such as NSUInteger? What am I doing wrong?


NSInteger is NOT an object. It's just another name for int. Just because something is prefixed by 'NS' do not assume its an object - there are many, many things in Cocoa that are prefixed 'NS' that are not objects - types, constants, functions, you name it. You can really tell what is or isn't an object purely from its name alone - check the documentation.

hth,

Graham

_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Newb Question re NSUserDefaults and Ints (From: Brad Gibbs <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.