Home>

Tap the save button and I want to save the text entered in UITextField called tab01
After tapping the save button, drop the app once and launch the app again
I'm having trouble getting back to the initial characters.

class ConfigViewController: UIViewController,
UITextFieldDelegate {
    // text field
    @IBOutlet weak var tab01: UITextField!
// Save button
    @IBOutlet weak var SaveButton: CustomButton!

    override func viewDidLoad () {
        super.viewDidLoad ()
        tab01.delegate = self
        // Do any additional setup after loading the view.
    }
    override func didReceiveMemoryWarning () {
        super.didReceiveMemoryWarning ()
        // Dispose of any resources that can be recreated.
    }
// save to user default
    @IBAction func memorizeText (_ sender: Any) {
        let writtenText = tab01.text! as String
        let defaults = UserDefaults.standard
        defaults.set (writtenText, forKey: "tab01Text")
        view.endEditing (true)
    }
// Display the saved text in the text field of the tab settings
    @IBAction func readText (_ sender: Any) {
        let defaults = UserDefaults.standard
        let value = defaults.string (forKey: "tab01Text")
        tab01.text = value
    }

Thank you.

Referenced articles
Save and load text with UserDefaults