If your needs are simple, consider this option before moving on to other storage methods.
(Swift 3.0)
Saving
@IBOutlet weak var nameTextField: UITextField! ... UserDefaults.standard.setValue(nameTextField.text, forKey: "name")
Retrieving
if let name = UserDefaults.standard.value(forKey: "name") as? String { nameTextField.text = name }
Tips
Save some typing and create a variable to access the defaults:- let defaults = UserDefaults.standard
(Swift 3.0)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.