I have an app that requires the user to enter data into four textfields of View1. When the data is entered in View1, the data is saved to userDefaults. No problem with this.
After the data is entered, View1 flips to View2 which displays calculated data based on the originally entered data. View2 shows the original textfields that were shown in View1 along with the calculated data based on the previously entered textfields. At this point, the user is free to change these same textfields if she so wishes. If she changes any of the data within these textfields it is saved to userDefaults.
The problem I have is that I am having to create two saveData() functions to do this, one in View1 and another in View2. I created a Utilities class in the Utilities.swift file to consolidate my code, but when I attempt to use the following code line:
defaults.set(foodnDrinkTextField.text, forKey: "foodnDrinkTextField")I get the this error: 'Use of unresolved identifier 'foodnDrinkTextField'.
I understand that this textfield is not present in my Utilities.swift file which generates the error. Is it possible to make this textfield "visible" in the Utilities.swift file?
Thanks for any help anyone can provide.