Consider a class with an array property 'xxxx' implemented KVC- compliantly by the following methods:

        - (NSUInteger) countOfXxxx;
        - (id) objectInXxxxAtIndex: (NSUInteger) index;

(Assume there's no NSArray instance variable backing this property.) So, users of the class can call [valueForKey:@"xxxx"] to get a proxy object that returns the objects in the "array".

Now, the question is: How do I implement a getter? The intention is that it's just a convenience method for getting a proxy:

        @property (readonly) (NSArray*) xxxx;

        - (NSArray*) xxxx {
                return [self valueForKey: @"xxxx"];
        }

but that is a *really* bad idea, because valueForKey: will *first* try calling the 'xxxx' method -- the one it was called from.

As I missing something simple here? It seems like there needs to be an 'arrayValueForKey:' method (parallel to mutableArrayValueForKey:), which checks whether the class implements the indexed accessors before calling the getter, instead of after.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to