Swift - Saving highscore using NSUserDefaults

后端 未结 5 1624
天命终不由人
天命终不由人 2020-11-28 15:27

I\'m using Swift to make a game. I want to save the users high score using NSUserDefaults. I know how to create a new NSUserDefaults variable in my AppDelegate file:

5条回答
  •  有刺的猬
    2020-11-28 15:41

    Swift 4

    Set Value

    UserDefaults.standard.set("TEST", forKey: "Key") //setString

    Retrieve

    UserDefaults.standard.string(forKey: "Key") //getString

    Remove

    UserDefaults.standard.removeObject(forKey: "Key")

提交回复
热议问题