On Apr 30, 2012, at 04:53 , Koen van der Drift wrote:

> Thanks for the link. I am confused now, since it says:
> 
> "Indexed Accessor Pattern
> [...]
> There are indexed accessors which return data from the collection (the
> getter variation) and mutable accessors
> that provide an interface for mutableArrayValueForKey: to modify the
> collection."
> 
> Which (I think) is what I am doing now. But it's too early and I
> haven't drank all my coffee yet :)

There are multiple ways of getting more or less the same result. The one you 
are using is slightly (and unnecessarily) circuitous, so mmalc is suggesting 
you use the more fundamental mechanism.

What's at stake here is KVO compliance. If you have a class MyClass with an 
indexed (array) property "things", you can implement the indexed mutable 
accessors -- basically 'insertObject:inThingsAtIndex:' and 
'removeObjectFromThingsAtIndex:'. (Note that the property name should be a 
plural noun for best readability.) Then, if you maintain the underlying array's 
contents *only* by calling these two methods -- either internally in the 
MyClass implementation, or externally from client objects after adding the 
methods to the MyClass public interface -- your MyClass class is fully 
KVO-compliant for the "things" property.

You can still have an "addMyObject:" public method if you want. In this 
scenario, it should just invoke 'insertObject:inThingsAtIndex:'.

OTOH, if you don't implement the KVO-compliant accessors, but do use the 
mutable array proxy -- this is your current approach -- then the proxy realizes 
you haven't implemented the accessors in your class, so it generates the KVO 
notifications itself. The result is that updates going through the proxy are 
KVO compliant.

(If you implement the accessors *and* use the proxy, the proxy object doesn't 
generate additional notifications. It knows that the accessors have that 
covered.)

Implementing the KVO accessor methods is a slightly more efficient approach, 
since it doesn't require the creating of a short-lived proxy object for every 
addition to the array.


_______________________________________________

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Reply via email to