On Oct 18, 2010, at 04:43, Trygve Inda wrote:

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

No, NSArrayController doesn't cache anything (well, it may cache something or 
other internally, but that has no relevance to its public functionality), and I 
can't think of any behavior that would cause it to unprovokedly copy objects.

The fact that issuing a KVO notification for the "myData" property "fixes" the 
problem most likely indicates that your code is changing the value of "myData" 
in a non-KVO compliant way, at some point. If the array controller has already 
bound to the old value at the time you do this, it won't know about the change.

I hope you won't mind if I go on to say that I think your entire design is 
misguided. For a start, as was pointed out in a different thread recently, you 
*really* can't rely on indexing into [someDictionary allValues]. There's 
*nothing* in the API that guarantees you'll get the dictionary objects in the 
same order every time you invoke 'allValues', even if the dictionary hasn't 
changed. Thus, your entire design is founded on an invalid assumption.

Further, as the discussion in a related thread seems to be trying to tell you, 
taking a shortcut by using naked NSMutableDictionary hierarchies is a lousy 
approach. Your data structure requirements are more complicated, and you'll 
likely do better (get to the solution faster) to create the class(es) needed to 
really encapsulate the behavior you want.


_______________________________________________

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 arch...@mail-archive.com

Reply via email to