Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

objective-c getter decorator for boolean values

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?

like image 929
Jim Avatar asked Nov 09 '11 16:11

Jim


1 Answers

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.

like image 119
Jef Avatar answered Nov 06 '22 13:11

Jef