I have a function that is supposed to keep track of a high score. When I played it the first time on my computer it worked and my high score was 4. Then I installed it on my phone to it test and the high score now is always 4, even if I beat it.
Inside viewDidLoad
:
let HighscoreDefault = NSUserDefaults.standardUserDefaults()
if(HighscoreDefault.valueForKey("Highscore") != nil)
{
circleView1.score = HighscoreDefault.valueForKey("Highscore") as! NSInteger!
scoreValue.text = Int(circleView1.score.value).description;
}
Inside function to update high score:
if(round>score)
{
score=round;
let HighscoreDefault = NSUserDefaults.standardUserDefaults()
HighscoreDefault.setValue(score, forKey: "Highscore")
HighscoreDefault.synchronize()
}