I have my user defaults defined as follow in ViewControllerSettings
public let kAlertsKey = "ALERTS_KEY"
And it is modified through a switch and an ìf
statement with the following code
if switchAlerts.isOn{
UserDefaults.standard.removeObject(forKey: kAlertsKey)
UserDefaults.standard.set("On", forKey: kAlertsKey)
UserDefaults.standard.synchronize()
print("on")
}else{
UserDefaults.standard.removeObject(forKey: kAlertsKey)
UserDefaults.standard.set("Off", forKey: kAlertsKey)
UserDefaults.standard.synchronize()
print("off")
}
My desire is to share the status On
or Off
to 6 different ViewControllers:
- ViewControllerGUI
- ViewControllerCreate
- ViewControllerList
- ...
My idea was to create an Enum such as:
enum ToggleSwitch: Int{
case On, Off
var isActive: Bool{
switch self {
case .On:
return true
case .Off:
return false
}
}
}
But I am not sure on how to follow or what I need to return in my enum case and where do I call it in each ViewController.
Thanks in advance!