[Solved] How to get boolean value from switch state?


You can simply call switch.isOn to get the state of the UISwitch, but you should rather create an IBAction for your UISwitch, which will be called every time the state of the Switch changes.

You can store the switch state in a computed property if you don’t need to be notified every time the state of the switch changes or store the value in a stored property, whose value you can change from the connected IBAction.

var switchState:Bool {
    return switch.isOn
}

You should also conform to the Swift naming convention, which is lowerCamelCase for function and variable names.

solved How to get boolean value from switch state?