How to create to-many accessor methods at runtime
How to create to-many accessor methods at runtime
- Subject: How to create to-many accessor methods at runtime
- From: Steve Weller <email@hidden>
- Date: Sun, 06 Jul 2008 10:56:13 -0700
I have an object that I would like to respond to a potentially large
number of KVC compliant to-many accessors of the form:
-countOf<key>
-objectIn<key>:atIndex:
so that they can be used with valueForKey: to return a proxy array, or
just called directly.
Rather than implement these as methods (and because <key> specifies
the array behavior), I want to be able to create them dynamically and
have all accesses to
-countOf<key>
-objectIn<key>:atIndex:
be handled by two central methods:
-countOfForKey:
-objectInForKey:atIndex:
that respond according to <key>.
I had thought that implementing forwardInvocation would do this, but -
forwardInvocation is only called if -respondsToSelector says NO. And
if -respondsToSelector says NO, then the tests for -countOf<key> and -
objectIn<key>:atIndex: will always fail and I will lose KVC compliance.
Another approach would be to override -valueForUndefinedKey:, but that
gives me the responsibility of creating and returning the proxy
NSArray that implements accesses to -countOfForKey: and -
objectInForKey:atIndex:
Is there a better way to be KVC compliant and yet create the methods
dynamically?
Steve Weller email@hidden
Technical Writing, Editing, Developer Guides, and a little Cocoa
_______________________________________________
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