How to use uiswitch to select a category in swift?

Trying to create an if else statement for UISwitch . Not quite sure what happens in if else statements to check if the switch is on.

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

Is it correct to use a switch?

+5
source share
1 answer

sender is a switch. Check if the switch is on 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 } } } 
+3
source

Source: https://habr.com/ru/post/1236190/


All Articles