Re: NSArray - move Items at indexes
Re: NSArray - move Items at indexes
- Subject: Re: NSArray - move Items at indexes
- From: Chris Hanson <email@hidden>
- Date: Fri, 21 Sep 2007 17:01:45 -0700
On Sep 21, 2007, at 12:54 PM, Gordon Apple wrote:
One thing I've learned is that if you are using array controllers
and
bindings with table views: DONT MESS WITH THE ARRAY DIRECTLY! Do it
through
the controller methods instead if you want the changes to track in
other
views.
The first part is correct but the second part is not. Model-level
changes DO NOT go through the NSArrayController. Model-level changes
should be done by manipulating the relationship the collection
represents; that is, the result of -mutableArrayValueForKey: or -
mutableSetValueForKey: for the relationship's key. *This* is what
actually causes the Key-Value Observing notifications to be posted.
It's also what the controllers actually do behind the scenes anyway.
A lot of people seem to be hacking together code that interacts with
controllers to perform model-layer manipulations because they've
"learned" by trial and error that it "works." This is why there is
such a huge emphasis on having a deep understanding of Key-Value
Coding and Key-Value Observing before using Cocoa Bindings and the
controller layer: If you try to approach the controller layer without
such an understanding, you will wind up with code that isn't
architected as well as it could be and that is hard to test and extend.
There is a process to learning Cocoa. Learn Cocoa according to that
process. Do not try to take shortcuts and backfill your knowledge;
you will wind up with gaps that lead you down incorrect paths. Cocoa
bindings are not difficult to understand or get right once you
understand KVC and KVO thoroughly, but if you don't understand them
they will be a mystery and whatever intuitive notion you develop of
them may be very incorrect.
-- Chris
_______________________________________________
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