Re: NSArrayController's add: swaps entire content array when array is accessed via keypath
Re: NSArrayController's add: swaps entire content array when array is accessed via keypath
- Subject: Re: NSArrayController's add: swaps entire content array when array is accessed via keypath
- From: Keary Suska <email@hidden>
- Date: Thu, 25 Jun 2009 11:00:44 -0600
On Jun 25, 2009, at 8:31 AM, Rick Hoge wrote:
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 would be ok, except that I observe changes to
topLevelDictionary.subArray (see below) and need to perform special
processing on new items inserted in the subArray. This only works if
-observeValueForKeyPath:ofObject:change:context:
is called with a change type of NSKeyValueChangeInsertion, and I can
access the inserted items using
[change valueForKey:NSKeyValueChangeNewKey]
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.
There are a number of ways I can work around this, but I don't
really understand why this difference in behavior (array accessed as
instance variable vs. keypath inside compound object) is happening.
Is this a bug? or does it make sense in some way? This all would
have been really simple if it worked as expected...
I believe your presumption here is incorrect. In both cases, the array
should be replaced on every change. Only if you implement indexed
accessors should this be different. Are you instead talking about KVO
notifications? You could get different kinds of notifications
depending on certain implementations.
In your example I would expect KVO notifications to be the same. Do
you implement standard set<key> accessors in your "instance variable"
test?
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
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