Instance variables:
var Score: Int64 = 0
var highscore: Int64 = 0
func saveHighScore(high:Int) {
NSUserDefaults.standardUserDefaults().setInteger(high, forKey: "highscore")
}
func highScore() -> Int {
NSUserDefaults.standardUserDefaults().integerForKey("highscore")
} func resetHighScore() {NSUserDefaults.standardUserDefaults().removeObjectForKey("highscore")
}
///METHOD. ALL OF THIS IS WORKING FINE. HIGH SCORE SHOWS AND UPDATES WHILE IN THE GAME.
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func Ans1(sender: AnyObject) {
if(CorrectAnswer) == "1" {
// Calculate the number of points
Score += 10
scoreLabel.text = "Score:\(Score)"
if (Score > highscore) {
highscore = Score
highScoreLabel.text = NSString(format: "High Score : %i", highscore) as String
}
Do I need to add anything here? For data to save and reload on relaunch of the application?