NSArray KVC proxy
NSArray KVC proxy
- Subject: NSArray KVC proxy
- From: Quincey Morris <email@hidden>
- Date: Sun, 25 Jan 2009 12:54:13 -0800
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 (email@hidden)
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:
This email sent to email@hidden