What is this syntax when I was attempting to override a getter?

前端 未结 1 605
渐次进展
渐次进展 2021-01-02 20:21

What is this syntax when I was attempting to override a getter??

I\'m just messing around trying to learn more about how properties work in Objective-C. Here is my

相关标签:
1条回答
  • 2021-01-02 20:56

    It's called "Getter Indexed Accessors" as explained in the Key-Value Coding Programming Guide

    From the documentation:

    In order to support read-only access to an ordered to-many relationship, implement the following methods:

    -countOf<Key> Required. This is the analogous to the NSArray primitive method count.

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

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

    You can implement such methods for performance reasons, as explained in the guide

    If benchmarking indicates that performance improvements are required, you can also implement -get<Key>:range:. Your implementation of this accessor should return in the buffer given as the first parameter the objects that fall within the range specified 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];
    }
    
    0 讨论(0)
提交回复
热议问题