NSUserDefaults not saving properly

Posted by BWC on Stack Overflow See other posts from Stack Overflow or by BWC
Published on 2009-09-13T21:34:20Z Indexed on 2010/04/13 5:12 UTC
Read the original article Hit count: 396

Filed under:
|

Hey Guys I'm having issues with NSUserDefaults and I don't quite understand what's going on

My App has 5 levels and each level does the exact same thing with NSUserDefaults (Retrieves the levels defaults, changes the value as the user plays the level and then sets the defaults and syncronizes at the end of the level) the first 4 levels...work without a hitch but the last level doesn't save the values. The app doesn't crash and the last level isn't the very last thing that happens, And I even have the defaults synchronized when the application terminates. Is there a max size on the NSUserDefaults or is there anything anyone can think of that I haven't, I'll post the code below but like I said the first four levels work perfectly

//header
NSUserDefaults *userData;


@property(nonatomic,retain) NSUserDefaults *userData;


//class file
//Sets the boolean variables for the class to use
userData = [NSUserDefaults standardUserDefaults];
boolOne = [userData boolForKey:@"LevelFiveBoolOne"];
boolTwo = [userData boolForKey:@"LevelFiveBoolTwo"];
boolThree = [userData boolForKey:@"LevelFiveBoolThree"];
boolFour = [userData boolForKey:@"LevelFiveBoolFour"];
boolFive = [userData boolForKey:@"LevelFiveBoolFive"];
boolSix = [userData boolForKey:@"LevelFiveBoolSix"];
boolSeven = [userData boolForKey:@"LevelFiveBoolSeven"];

//End Of Level
[userData setBool:boolOne forKey:@"LevelFiveBoolOne"];
[userData setBool:boolTwo forKey:@"LevelFiveBoolTwo"];
[userData setBool:boolThree forKey:@"LevelFiveBoolThree"];
[userData setBool:boolFour forKey:@"LevelFiveBoolFour"];
[userData setBool:boolFive forKey:@"LevelFiveBoolFive"];
[userData setBool:boolSix forKey:@"LevelFiveBoolSix"];
[userData setBool:boolSeven forKey:@"LevelFiveBoolSeven"];
[userData synchronize];

When when I switch to the view that uses these defaults they values are correct but when I terminate the application and restart it, these values aren't saved, every other level does the exact same process this is the only level that doesn't work.

I've stared at this for quite awhile and I'm hoping someone out there has run into the same problem and can give me some insight on how they resolved it.

Thank you in Advance BWC

© Stack Overflow or respective owner

Related posts about iphone

Related posts about nsuserdefaults