I am trying to use an array controller to bind to an array that I manage, and it appears from the documentation that I need to have a proxy object that responds to all the standard array methods, so I created that, and if I have the array methods named along the lines of the key binding, then at least my get method is being called (though I still don't think that the array controller understands that it is an array rather than an instance variable).

But I want to have this a generic array proxy, where it can be configured to hold any array of data, so I have set it up with two instance variables: the real array (NSMutableArray) and the key that it has been configured to respond to (NSString). I have implemented all the array methods for - (NSArray *)realArray, - (id)objectInRealArrayAtIndex:(unsigned)theIndex etc. and then implemented respondsToSelector: to return YES for any of the methods it should respond to for the configured key, and methodSignatureForSelector: to replace realArray with the actual key I want to respond to, and forwardInvocation: to invokeWithTarget:self now that the method signature has been rewritten. I think all that is pretty straightforward, but... the key value stuff never calls respondsToSelector: or methodSignatureForSelector: - it appears that it must be using some of the objc stuff like objc_method_list or something like that which is completely bypassing the dynamic side of the method lookups, and instead I get thrown into the valueForUndefinedKey:. Can someone confirm that it is bypassing the dynamic method lookups?

If this is the case, then my generic proxy just isn't going to work, but unless arrangedObjects has some special processing going on, I would have thought that the KVC/KVO runtime must support dynamic method lookup, because it must do it for the _NSControllerArrayProxy class.

The other thing I don't fully understand is how the normal KVC methods work out whether it is an array, set, or value at the other end of the relationship. In my array controller subclass, when it asks for valueForKey: I return my array proxy object, but the normal valueForKeyPath method seems to think it is a value rather than an array, and doesn't call the array methods. So if I override the valueForKeyPath: method, I'm not sure what I should return, because if I return [myArrayProxy mutableArrayValueForKey:key] then it thinks it has an array rather than an array proxy, and starts sending messages like "count" to it. But if I return the proxy object, it sends a descriptionWithLocale: to it (which does actually go through the respondsToSelector: method, so I know that is working) and then complains that it can't create a number from an object, which seems to be further proof that it thinks it's an object and not an array.

I would have thought that it was possible to do what I am trying to do, but am now having second thoughts because of all these issues. Any suggestions and/or sample code would be very welcome.

Regards
Gideon
_______________________________________________

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