Quincey, Keary, thanks for the replies -

...

All worked fine, except that, when the new dictionaries are added by clicking the add: button, the mutable array managed by the controller is replaced with a new array (rather than inserting the new dictionary in the original array). The new array has the correct content, apparently having copied all the pre-existing dictionaries from the old array.

This is correct. NSMutableDictionary implements 'setValue:forKey:' (as a convenience, to provide very basic KVC compliance) but it doesn't implement any indexed accessors, so the array is updated via this 'setValue:forKey:', which means that the array is completely replaced.

If you look at:

http://developer.apple.com/documentation/Cocoa/Conceptual/KeyValueCoding/Concepts/SearchImplementation.html#/ /apple_ref/doc/uid/20000955-SW2

you'll see that case (1) doesn't apply, but case (2) does.

I confirmed that if subArray is promoted to an instance variable, then add: will perform an insertion rather than creating a new array (in fact I've used this a lot in the past). It seems that having the array be part of a mutable compound object results in creation of a new, copied array instead of an insertion.

Presumably you haven't overridden 'accessInstanceVariablesDirectly:' to return NO in your "certain object", so now case (3) applies, and that results in the array being updated instead of replaced.

The problem you've got is that you want "subArray" to behave like a fully KVO compliant indexed property, but you haven't implemented it as such.

I guess I was lulled into thinking it wouldn't require any coding, since the array controller always did insertions when it was bound to an instance variable. Now it makes sense that the dictionary behaves differently from the object.

Thanks again,

Rick


Cocoa-dev mailing list ([email protected])

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/rickhoge1%40mac.com

This email sent to [email protected]

(43092.6825)

_______________________________________________

Cocoa-dev mailing list ([email protected])

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