IPhone SDK Default NSUserDefaults...

Posted by Harry on Stack Overflow See other posts from Stack Overflow or by Harry
Published on 2010-04-10T18:35:27Z Indexed on 2010/04/10 18:53 UTC
Read the original article Hit count: 510

I have set up the user defaults to record a integer for a UISlider, the problem is that, if the user has only just installed the app then the integer is zero or NULL. Is there a way to detect if it = NULL with a integer?

heres my code i have so far:

-(void)awakeFromNib {
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
senset = [prefs integerForKey:@"senset"];
senset = sensitivity.value;
}
- (IBAction) setSens {
senset = sensitivity.value;
}
- (IBAction) goBackopt {
{
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    [prefs setInteger:senset  forKey:@"senset"];
    [prefs synchronize];
}

 }

senset is the integer. i have tried this code, and it sets it to 25 on the first time, but then if i try and overwrite it, it wont work and keeps setting it to 25. :(

    if ( [prefs integerForKey:@"senset"] == NULL ) {
    senset = 25;    
}

Please help :P

Harry

© Stack Overflow or respective owner

Related posts about iphone-sdk

Related posts about nsuserdefaults