I have an app where there are 2 views, one with a UILabel and another with a UITextField. I would like it so the moment you are done editing the Text Field, the label changes to the TF's value. The text field stores its value in a UserDefaults and when my Label's View loads, it shows the value of the UD key on the label. Again, I would like it so the moment you are done editing the Text Field, the label changes to the TF's value.
Below is my Label's View's Controller
My TextField's View's Controller
Below is my Label's View's Controller
Code Block Swift struct myStruct { static var money = 0.00 } import UIKit class ViewController: UIViewController { @IBOutlet weak var moneyLabel: UILabel! override func viewDidLoad() { super.viewDidLoad() let ud = UserDefaults.standard myStruct.money = ud.double(forKey: "Money") moneyLabel.text = String(ud.double(forKey: "Money")) } }
My TextField's View's Controller
Code Block swift import UIKit class AddMoneyViewController: UIViewController { let userDefaults = UserDefaults.standard @IBOutlet weak var TextField: UITextField! override func viewDidLoad() { super.viewDidLoad() } @IBAction func TFEditingDidEnd(_ sender: Any) { userDefaults.set(TextField.text, forKey: "Money") let moneyAtPoint1 = userDefaults.double(forKey: "Money") print(moneyAtPoint1) } }