I do have the indexed accessors implemented. I also have an accessor that returns an array of the objects -- not sure why I did that... force of habit from other accessors (having a setter -set<Key> and a getter -<Key>). I certainly can understand one reason why this wouldn't be good, because should some code somewhere acquire this immutable array, and hang on to it, then that list of objects could easily become out of sync.

That said, I "instrumented" my accessor and the index accessors to see what is being used. Oddly (at least to me), if I do have the array-returning-accessor implemented, it is actually invoked by Cocoa code: -[NSBinder _valueForKeyPath:ofObject:mode:raisesForNotApplicableKeys:] Perhaps because the mutable array property is the content model for an NSArrayController, which has its arrangedObjects bound to a Table View.

I'm curious why, if it is advised to not have the -<Key> accessor, that Cocoa itself invokes the -<Key> accessor preferentially to the index accessors?


On Jun 26, 2008, at 9:49 PM, Scott Anguish wrote:

the better way is to implement the indexed accessors described in the KVC doc.

in fact I know at least one engineer would would like the doc to specifically say that you should NOT have an accessor that returns an array like this.


On Jun 26, 2008, at 7:54 PM, Stuart Malin wrote:

Separately, I have an accessor -attendees: of the Party class, which is currently implemented as:

- (NSArray*) attendees
{
return [NSArray arrayWithArray:attendees]; // "attendees" is an NSMutableArray, and is an ivar
}

I intentionally do not return the underlying mutable array, because I don't want other code accessing the content without going through the accessors.

Is my implementation reasonable? Or are there preferable ways to do this (such as to return a copy of the mutable 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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to