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 property:
@property (nonatomic, strong) UIView *myView;
When I try to override the getter I get this help:
-(void)getMyView:(<object-type> **)buffer range:(NSRange)inRange
{
}
I know I can use this:
-(UIView *)myView
{
}
But I am just curious as to what the previous method does, why it's there, etc. Thanks for any help!
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 methodsobjectAtIndex:
andobjectsAtIndexes:
-get<Key>:range:
Implementing this method is optional, but offers additional performance gains. This method corresponds to theNSArray
methodgetObjects: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];
}
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