I'm making a weather app, and currently I'm adding support to switch from Imperial measurement to Metric, but when you switch from the settings view controller to the main menu to the weather viewer, it resets the unit variable to Imperial.
I have looked at many questions and articles, and either:
- I don't understand how to do it
- It doesn't work or needs an older version of Swift
- It causes the whole app to break
========================================================================
Note: I am using segues to switch VCs
@IBAction func unitSwitcherMetric(_ sender: UIButton) {
weatherDataModel.unit = "metric"
weatherDataModel.windUnit = ""
print("The unit is now \(weatherDataModel.unit)")
}
After you select that button, it prints
The unit is now metric
as expected, but when you switch to the main menu view controller, where it's supposed to print the unit variable, it prints imperial
and the API supplies imperial measurements as well.