NSUserDefaults Not Saving TextField Text (Swift)

前端 未结 5 2002
天涯浪人
天涯浪人 2021-01-01 05:52

I\'m trying to create a game with Swift, and I want to add the ability to create a username, which will be saved in NSUserDefaults. This is my code:

println(&         


        
5条回答
  •  [愿得一人]
    2021-01-01 06:03

    In Swift 4.1
    
     UserDefaults.standard.set(textfield.text, forKey: "yourKey") // saves text field text
      UserDefaults.standard.synchronize()
    
    // To Retrieve
    textfield.text = UserDefaults.standard.value(forKey:"yourKey") as? String
    

提交回复
热议问题