如何使用 uiswitch 在 swift 中选择类别?

how to use uiswitch for selecting category in swift?

正在尝试为 UISwitch 创建 if else 语句。不确定 if else 语句中的内容以检查开关是打开还是关闭。

@IBAction func selectionLabel(sender: AnyObject) {
    if(<some condition>)
    // do something

    else
      //do something
}

这是使用开关的正确方法吗?

sender就是开关。通过检查 on 属性:

检查开关是否打开
@IBAction func selectionLabel(sender: AnyObject) {
    if let mySwitch = sender as? UISwitch {
        if mySwitch.on {
            // switch is on
        } else {
            // switch is off
        }
    }
}