Trying to create an if else statement for a UISwitch. Not exactly sure what goes in the if else statements to check whether the switch is on or off.
@IBAction func selectionLabel(sender: AnyObject) {
    if(<some condition>)
    // do something
    else
      //do something
}
Is this a correct way to use the switch?
The sender is the switch.  Check if the switch is on by checking the on property:
@IBAction func selectionLabel(sender: AnyObject) {
    if let mySwitch = sender as? UISwitch {
        if mySwitch.on {
            // switch is on
        } else {
            // switch is off
        }
    }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With