views:

28

answers:

1

I would like to retrieve an Int value from NSUserDefaults, but it always comes up as 0.

This is how my settings bundle looks:

Type:          String: PSMultiValueSpecifier
Title:         String: Timer
Key:           String: timerValue
DefaultValue:  Number: 4
Titles:         Array:  5 Number Items 1-5
Values:         Array:  5 Number Items 1-5

I use this to access the default...

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSInteger timerValue = [defaults integerForKey:@"timerValue"];

NSLog(@"timerValue is : %i", timerValue);

Always 0. I have been into Settings and actually changed the value, but still always 0.

Thanks.

A: 

You get an NSNumber returned, not an NSInteger

JustSid
I do this, and its still 0: `NSNumber *timerValue = [NSNumber numberWithInt:[defaults integerForKey:@"timerValue"]];`
joec
No, I meant: `NSInteger value = [[defaults valueForKey:@"timerValue"] intValue]`
JustSid
Another comment... shame on me, I didn't saw that you already had integerForKey. Sorry! Never mind my answer
JustSid