I have a UISwitch that I want to control a boolean value in a function I wrote. I looked in the UISwitch Type Reference and it listed the property
If you are trying to change the switch you can use
mySwitch.on = true
to set it to "on" or
mySwitch.off == false
to set it to "off"
Or if you want to get the value you can use
let myBool = mySwitch.on
If the switch is powered on the value will be true, otherwise false.
You can also make an action called valueChanged (to get or update the value whenever the switch value is changed)
@IBAction func valueChanged(sender: AnyObject) {
// some code
}
You can do this by select the dualView... view and ctrl drag from your switch to you view controller and choose action, and value changed if that's not already selected.