I have two storyboards in my game: the home page and the game itself. When a user gets a high score in the game i save it as their high score. How can i then take that high score to display it on the homepage without linking the view controllers to the same code.
Save highscore anywhere in your project
[[NSUserDefaults standardUserDefaults] setInteger:score forKey:@"kHighscoreKey"];
[[NSUserDefaults standardUserDefaults] synchronize];
Retrieve highscore anywhere else in your project
NSUInteger highScore = [[NSUserDefaults standardUserDefaults] integerForKey:@"kHighscoreKey"];
If your do not find your score data important or sensitive use NSUserDefaults
First scene:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setInteger:yourHighScore forKey:@"HighScore"];
Second scene:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
yourHighScore = [defaults integerForKey:@"HighScore"]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.