In my main view, I am collecting data from two other views. I start in the main view, go to the next view to get the data and go back to the original view. Then I go to the last view and get more data, but when I go back the original data is gone. How do I save it before leaving?
I have tried using viewWillDisappear
but it wasn't working. Is this a good approach and if so, how do I go about using it?
These are the two pieces of data coming in via segue:
var homeTeamName = String ()
var awayTeamName = String ()
I do this when I load:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib. }
HomeName.text = homeTeamName
HomeImage.image = UIImage(named:homeTeamName)
AwayName.text = awayTeamName
AwayImage.image = UIImage(named:awayTeamName)
}
Note:
Everything with away is coming from one view, and everything with home is coming from another.
Now I am storing like this:
override func viewWillDisappear(_ animated: Bool) {
UserDefaults.standard.set("value", forKey: "homeTeamName")
}
Retrieving like this:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
UserDefaults.standard.string(forKey: "homeTeamName")
}
Still not working.
Thanks in advance!