Question

I'm perusing the UISwitch documentation, specifically determining whether a switch is on or off.

Most resources suggest using isOn for this, but the docs give more prominence to on:

on

A Boolean value that determines the off/on state of the switch.

@property(nonatomic, getter=isOn) BOOL on

What does this definition mean, exactly? It reads as though there is a property 'on' with a renamed getter? What is the purpose of this? Why not just use on?

And if the setter is isOn, why can I access on at all?

I have similar confusion regarding isEditing and editing - is the same pattern in play there?

Was it helpful?

Solution

@property(nonatomic, getter=isOn) BOOL on

It means that property is called on, but getter is isOn. So whatever you call, in your code methods isOn will be called

I suggest that getter is named isOn, because it is good style of code convention to start boolean properties with is...

Here is nice sample

As for me to start all boolean properties with is is very useful, because when you use your class, you can write the name of the instance variable of your class , than write is and XCode will show you all the boolean properties..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top