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.
UISwitch
@IBAction func selectionLabel(sender: AnyObject) { if(<some condition>) // do something else //do something }
Is it correct to use a switch?
sender is a switch. Check if the switch is on checking the on property:
sender
on
@IBAction func selectionLabel(sender: AnyObject) { if let mySwitch = sender as? UISwitch { if mySwitch.on { // switch is on } else { // switch is off } } }
Source: https://habr.com/ru/post/1236190/More articles:Block with two parameters - ruby | fooobar.comHow to close socket.io connection - node.jsCan someone explain why this way of iterating a nested data structure really works? - arraysSoap Client Consumes Rest Web Services - soapHow to debug web applications efficiently? - javascriptDifference in ES6 Promises and PEP3148 Futures Chain - javascriptMalloc outside main () or any other function (i.e., globally) - c ++MySQL 5.7.9 on OS X El Capitan: ERROR Server shuts down without updating PID file - mysqlReading scientific notation of csv file with numpy - pythonAWS S3 "ObjectCreated" Not Always Accepted Lambda - amazon-s3All Articles