I am trying to leran how to use UserDefaults
with Swift. I need to save the state of a bool statement.
I have a UISwitch
that if it is on, the bool statement is true. If it is off, it is false. Like this:
I declare a gloabal variable...
var switchBool : Bool = false
Then I set up the action for the switch...
@IBAction func boolSwitchAction(_ sender: Any) {
if darkModeSwitch.isOn {
switchBool = true
} else {
switchBool = false
}
}
It works great. But then, once the app is shut down, the app does not remember that the switch is on, nor if the switchBool
is true. That's why I need to use UserDeafaults. I've looked for some tutorials, but I couldn't find one that would help me. Can someone help me with this? Thanks!