Swift 3.0 save a score with SpriteKit

前端 未结 1 1314

I am trying to save a \"highScore\" integer that persists after the app is closed using SpriteKit.

That\'s it. Just one single integer on one single screen that I will e

相关标签:
1条回答
  • 2021-01-23 16:35

    You can use UserDefaults class for that purpose.

    If you have any sort of GameManager singleton, you can define a computed variable which saves and reads from UserDefaults:

    var highScore: Int {
        get {
            return UserDefaults.standard.integer(forKey: "highScore")
        }
        set {
            UserDefaults.standard.set(newValue, forKey: "highScore")
        }
    }
    
    0 讨论(0)
提交回复
热议问题