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:

About Jay Versluis

Jay is a medical miracle known as Super Survivor. He runs two YouTube channels, five websites and several podcast feeds. To see what else he's up to, and to support him on his mission to make the world a better place, check out his Patreon Campaign.

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.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.