Reputation:
i have a integer called HighScore which is connected to highscorelabel . i have made it so when the user gets a high score it puts the score they got onto the label but i would now like to know how i can save it so that when the app is opened again it will still have the high score : this is my code for detecting when a high score is made
(void) submitScore {
if (lives > HighScore){
HighScore = lives;
}
highscorelabel.text = [NSString stringWithFormat:@"%i" , HighScore];
}
Upvotes: 0
Views: 2557
Reputation: 37494
Use NSUserDefaults for saving:
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setInteger:HighScore forKey:@"HighScore "];
[prefs synchronize];
and retrieving:
HighScore = [prefs integerForKey:@"HighScore"];
Upvotes: 1