What is this syntax when I tried to override the getter?

What is this syntax when I tried to override getter ??

I just messed around trying to learn more about how Objective-C properties work. Here is my property:

@property (nonatomic, strong) UIView *myView; 

When I try to override getter, I get this help:

 -(void)getMyView:(<object-type> **)buffer range:(NSRange)inRange { } 

I know I can use this:

 -(UIView *)myView { } 

But I'm just wondering what the previous method does, why it is there, etc. Thanks for any help!

+6
source share
1 answer

It is called "Getter Indexed Accessors" as described in Key Value Coding Programming Guide

From the documentation:

To support read-only access to ordered-number relationships, follow these methods:

-countOf<Key> Required. This is similar to counting the primitive NSArray method.

-objectIn<Key>AtIndex: or -<key>AtIndexes: One of these methods must be implemented. They correspond to the methods NSArray objectAtIndex: and objectsAtIndexes:

-get<Key>:range: Implementing this method is optional, but provides an additional performance boost. This method corresponds to the NSArray getObjects:range: method.

You can implement such methods for performance reasons, as described in the manual.

If benchmarking indicates a need for performance improvement, you can also implement -get<Key>:range: Your implementation of this accessory should return in the buffer specified as the first parameter, objects that fall into the range indicated by the second parameter.

As an example

 - (void)getEmployees:(Employee * __unsafe_unretained *)buffer range:(NSRange)inRange { // Return the objects in the specified range in the provided buffer. // For example, if the employees were stored in an underlying NSArray [self.employees getObjects:buffer range:inRange]; } 
+5
source

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


All Articles