Objective-c getter decorator for boolean values

I looked at the Objective-C documentation for programming documentation to better understand the declaration and implementation of properties. I stumbled upon this line and thought it might be important for my code:

Usually, you should specify the accessor method names that are key (see Key Value Encoding Programming Guide) - a common reason for using a getter decorator is to stick to isPropertyName for boolean values.

So far, I just used this:

@property (nonatomic, assign) BOOL aBooleanProperty;

But I always had the feeling that this might not be entirely correct.

I do not understand that the last part (highlighted) in the documentation. How does this suggest that I should provide a getter decorator and what would it do for me?

+6
source share
1 answer

This means that you can use a custom name for the recipient, for example

@property (nonatomic, assign, getter=isValue) BOOL value;

To get it, you name it as [someObject isValue] instead of [someObject value] . Apple does this using NSButton (NSControl)'s isEnabled , for example.

+9
source

Source: https://habr.com/ru/post/901130/


All Articles