我在尝试比较我的得分和高分时遇到一些问题,看看哪一个更大然后保存.我认为问题在于比较和保存高分和得分.非常感谢帮助!
//Comparison between score and highscore
if score > highscore {
let defaults: NSUserDefaults = NSUserDefaults.standardUserDefaults()
highscore = defaults.valueForKey("highscore")?.integerValue ?? 0
defaults.setInteger(score, forKey: "highscore")
defaults.synchronize()
highscoreString = String(highscore)
highscoreLabel.text = highscoreString }
Run Code Online (Sandbox Code Playgroud)
全页代码 - https://github.com/SRL311/Highscore/blob/master/Highscore (对不起那里令人困惑的大写字母和小写字母)