i’m trying to retrieve a value from my preference file which is an integer. The funny thing is that it always returns zero, although it does exist and the names for both integerForKey: and setIntegerForKey: are the same.
Here’s how I retrieve the value: [defaults integerForKey:@"BackUpSize"];
And here I set it: [defaults setInteger:[sizeSlider doubleValue]*8589934592 forKey:@"BackUpSize"];
I’m stunned. It should work…or am I missing something here?
Thanks
Edit: defaults is created as such: NSUserDefaults*defaults = [NSUserDefaults standardUserDefaults];
Edit: I’ve tried creating my own NSUserDefaults method for this issue, but it still returns zero.
-(void)setDouble:(double)dou forKey:(id)key
{
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithDouble:dou] forKey:key];
}
-(double)doubleForKey:(id)key
{
return [[[NSUserDefaults standardUserDefaults] objectForKey:key] doubleValue];
}
8589934592is a hard-coded literal? Really? You should at least put something like1 << 33. Even then, declare it as a constant, for crying out loud.If you’re building for 32 bit,
NSIntegeris a 32 bit signed value. So you are rather likely to be overflowing. I’m not sure what the behaviour of NSUserDefaults would be in that case, but it’s worth considering.