Newb Question re NSUserDefaults and Ints
Newb Question re NSUserDefaults and Ints
- Subject: Newb Question re NSUserDefaults and Ints
- From: Brad Gibbs <email@hidden>
- Date: Fri, 29 Aug 2008 18:54:29 -0700
I'm having a hard time with what should be a simple task - storing an
integer for a gradient angle as a user default and then updating the
screen. When I quit the app and open it again, the NSTextField shows
the last value I set for the gradient, but with the following code:
- (IBAction)changeElementBarGradientAngle:(id)sender {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
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
I've also tried turning the int into an NSNumber object and using
defaults setObject: foKey: without success.
It seems as though I have to use:
[gradient drawInRect:[self bounds] angle:
[ICNElementBarGradientAngleKey intValue]];
turning ICNElementBarGradientAngleKey back into an int, which makes me
wonder, is setInteger in:
[defaults setInteger:[elementBarGradientAngleTextField intValue]
forKey:ICNElementBarGradientAngleKey];
meant to be used with an int, or an object, such as NSUInteger? What
am I doing wrong?
Thanks,
Brad
_______________________________________________
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