ios - NSUserDefaults - Saving and retrieving "High Scores" -
I'm just learning the program and doing some SWIFT tutorials. I've researched as much research as I did, but it seems that some important aspects are missing. I have a simple game and when a player dies, I want to see their score against the high survivors already.
The highest score is displayed on a title screen.
This is the current code I am using;
NSUserDefaults.standardUserDefaults (). IntegerForKey ("highest score") if score & gt; ("Highest Score") (NSUser Defaults: Standard Standard Default). Set Intager (Score: For: "Highscore") NSUserDefaults.standardUserDefaults (.) Synchronize ()} NSUserDefaults.standardUserDefaults (.) IntegerForKey ("highscore" ) The problem I can not solve is just how to print the highscore! I have tried;
hiScoreText.text = "Hi Score: \ (Highest score) " But I found out that this is not correct. Which variables can I use or how to escape Or the highest score "read"?
Any advice for a new person will be greatly appreciated.
I think that you have forgotten to save the retrieved high score in the variable:
highColor = NSUserDefaults.standardUserDefaults (). IntegerForKey (" Highest Score ") < / Code>
Comments
Post a Comment