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 @synthesize
directives in the implementation file). The getter=isOn
inside the @property
does indeed mean that the getter method has the name isOn
.
Properties by default will create a getter with the same name as the ivar and a setter with set
prepended. Changing the getter name (or its setter, with the setter=
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.