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:

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.