I'm trying to take the NSUserDefaults.standardUserDefaults
route of storing data into an iOS device. I know this is not the best method, but I'm just trying it out for practice (I know the data is erased when you restart the simulator or delete the app from the device). My main goal is to get the data stored within the iOS device and then pull it back up displayed on another view controller after submission. I thought that I could maybe display it as a Label, but I'm still having trouble recalling that information when stored and pulling in up in a different view controller. Sorry if this is not enough information, I can supply more if needed in a bit.
I'm typing the value into a textfield
@IBOutlet weak var userNameTextField: UITextField!
And then I submit the data with a button
@IBAction func submitButton(sender: AnyObject) {
let userName = userNameTextField.text;
NSUserDefaults.standardUserDefaults().setObject(userName, forKey: "userName")
NSUserDefaults.standardUserDefaults().synchronize()
}
Is synchronize necessary or is that only needed with multiple text fields being submitted?
Again, I just want to take the submitted data and be able to see/view/display it on another view controller page.