• 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
NSArrayController making copies of my objects?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSArrayController making copies of my objects?


  • Subject: NSArrayController making copies of my objects?
  • From: Trygve Inda <email@hidden>
  • Date: Mon, 18 Oct 2010 11:43:39 +0000
  • Thread-topic: NSArrayController making copies of my objects?

I am trying to figure out exactly what is happening here.

I have a mutable dictionary where each object is also an NSMutableDictionay
containing 9 string objects.

NSMutableDictionary*  myData;    // this is in MyController object.

In a window, I have an NSTableView whose column data is tied to an
NSArrayController. The NSArrayController is bound to myData with IB:

Bind to MyController, keypath: myData.@allValues

This all works fine, except....

I would expect the following to have the same addresses:

NSMutableDictionary*    myItemA =
[[[MyController myData] allValues] objectAtIndex:0];

NSMutableDictionary*   arrayContItemA =
[[myArrayController arrangedObjects] objectAtIndex:0];

The content is the same (the 9 strings) so it is coming from the right
place, but the addresses of the objects are different so for some reason the
NSArrayController is making a copy of my dictionary object somewhere along
the line.

I understand that the array returned by allValues is not mutable so the
NSArrayController may need to make a mutable copy of it, but the internal
objects are mutable... So why is it copying my objects?

If I add the following just before the above two lines, then the objects
have the same address as expected.

[MyController willChangeValueForKey:@"myData"];
[MyController didChangeValueForKey:@"myData"];

So I gather this is forcing the NSArrayController to write it's
copied/cached values back to myData.

The point is that I need to be able to edit the items in the NSTable, then
write myData back to disk and have the changes be saved. If I never call
will/didChangeValueForKey, then the changes are lost.

Since I am not changing myData directly but it is being changed by the
NSTableView and NSArrayController, why does this happen this way?

Thanks,

Trygve


_______________________________________________

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

  • Follow-Ups:
    • Re: NSArrayController making copies of my objects?
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Image Resolution
  • Next by Date: Re: Codesign additional items within an app bundle
  • Previous by thread: Re: Image Resolution
  • Next by thread: Re: NSArrayController making copies of my objects?
  • Index(es):
    • Date
    • Thread