I noticed that for a property with a custom getter method
@interface MyClass : NSObject
@property (nonatomic,getter=isActive) BOOL active;
@end
both
BOOL b = myObj.isActive
and
BOOL b = myObj.active
can be used to get the value. In both cases the isActive method is called.
- Is there any difference between these two ways of getting the property value?
- What is the “recommended” way?
There is no difference between the two. You use a custom name when you want to break the established convention of
XYZ+setXYZin cases when the alternative names make more sense from the point of view of English grammar. For example,reads better than
You could have declared your property as
isActive, but then your setter would besetIsActive, which sounds slightly worse thansetActive.