开发者

Retrieve Int from NSUserDefaults MultiValue

开发者 https://www.devze.com 2023-01-22 04:54 出处:网络
I woul开发者_高级运维d like to retrieve an Int value from NSUserDefaults, but it always comes up as 0.

I woul开发者_高级运维d 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.


I was experiencing the same problem you describe. It appears the default value is not being set through the bundle. If you change the values through the Settings view and then run your code, you'll probably find it works.

I got around it by setting my default values in the applicationDidFinishLaunching method.

0

精彩评论

暂无评论...
验证码 换一张
取 消