I was reviewing the Objective-C Programming Language documentation to get a better understanding of property declaration and implementation. I came across this line, and thought it might be important to the way I code:
Typically you should specify accessor method names that are key-value coding compliant (see Key-Value Coding Programming Guide)—a common reason for using the getter decorator is to adhere to the isPropertyName convention for Boolean values.
Until now, I have simply used this:
@property (nonatomic, assign) BOOL aBooleanProperty;
But I have always had a sense that this may not be quite right.
I don't understand that last part (highlighted) in the documentation. How does that suggest that I should provide a getter decorator, and what would that do for me?
It means that you could use a custom name for a getter like
@property (nonatomic, assign, getter=isValue) BOOL value;
So to get it you call it like [someObject isValue]
instead of [someObject value]
. Apple does this with NSButton (NSControl)'s
isEnabled
for example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With