NSUserDefaults doesn't save

Posted by JJSaccolo on Stack Overflow See other posts from Stack Overflow or by JJSaccolo
Published on 2010-05-18T21:54:58Z Indexed on 2010/05/18 22:00 UTC
Read the original article Hit count: 165

Hi everybody! i'm trying to save some informations in an iphone/ipad app. The problem is that it works but if i close the app (with the home button on the simulator or closing with cmd+q) the informations become lost!

this is my code (and, if you see, i used "syncronize")

- (IBAction)choose1{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:@"choose1" forKey:@"choose"];
    [defaults synchronize]; 
}

- (IBAction)choose2{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:@"choose2" forKey:@"choose"];
    [defaults synchronize];
}

- (IBAction)openview{
    NSString *var = [[NSUserDefaults standardUserDefaults] objectForKey:@"choose"];
    if (var == @"choose1"){
        [self pushViewController:view1 animated:YES];}
    else if (var == @"choose1"){
        [self pushViewController:view2 animated:YES];
    }

}

I don't understand why :(

© Stack Overflow or respective owner

Related posts about nsuserdefaults

Related posts about xcode