I’m a beginner following a book for creating iPhone apps.
One of the steps was writing “UISwitch *whichSwitch = whichSwitch.isOn;” and I was just curious as to where “isOn” came from?
In the documentation:
on
A Boolean value that determines the off/on state of the switch.
@property(nonatomic, getter=isOn) BOOL on
What does that “getter=isOn” part mean? My ultimate reason for asking this question is because I want to know what I should do when I come across a similar situation for different UI elements.
Oh yeah, is this like the thing where properties create a “setSomething” mutator and “something” accessor? Except that for booleans it is “isOn” and “on”?
Thanks.
Properties are basically shorthand for generating methods later (the actual creation is done by
@synthesizedirectives in the implementation file). Thegetter=isOninside the@propertydoes indeed mean that the getter method has the nameisOn.Properties by default will create a getter with the same name as the ivar and a setter with
setprepended. Changing the getter name (or its setter, with thesetter=syntax) is all this property directive does. You should do this only for boolean or similar variables – other variables should have a getter with the same name as the variable.