• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSArrayController's add: swaps entire content array when array is accessed via keypath
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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: Rick Hoge <email@hidden>
  • Date: Fri, 26 Jun 2009 10:28:52 -0400


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@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

(43092.6825)

_______________________________________________

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


References: 
 >NSArrayController's add: swaps entire content array when array is accessed via keypath (From: Rick Hoge <email@hidden>)
 >Re: NSArrayController's add: swaps entire content array when array is accessed via keypath (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: Number of images in main bundle folder (iPhone)
  • Next by Date: Re: Number of images in main bundle folder (iPhone)
  • Previous by thread: Re: NSArrayController's add: swaps entire content array when array is accessed via keypath
  • Next by thread: resizing table view programmatically
  • Index(es):
    • Date
    • Thread