How to test the state of a UISwitch

We can use the isOn property of your switch to do this:

Alternatively we can use the square-bracket notation like so:

Jay is the CEO and founder of WP Hosting, a boutique style managed WordPress hosting and support service. He has been working with Plesk since version 9 and is a qualified Parallels Automation Professional. In his spare time he likes to develop iOS apps and WordPress plugins, or draw on tablet devices. He blogs about his coding journey at http://wpguru.co.uk and http://pinkstone.co.uk.

2 thoughts on “How to test the state of a UISwitch

  1. You know what it’s like… a few months later this doesn’t work anymore, or it’s the other way round. I H-A-T-E Xcode and this Objective-C 5H1T so very very very much.

    That aside, here’s another solution which works (today that is):

  2. There is another way by checking if the sender’s property isOn or not, like so:

    This is useful if you don’t want to define the switch as a property. All you need to do is connect it to an action which will check the above.

Add your voice!