Re: Get Objects from NSArrayController
Re: Get Objects from NSArrayController
- Subject: Re: Get Objects from NSArrayController
- From: Chris Hanson <email@hidden>
- Date: Mon, 24 Apr 2006 16:53:49 -0700
On Apr 24, 2006, at 4:24 PM, Jason Barker wrote:
Newbie question: How does one go about getting the objects from an
instance of NSArrayController as an NSMutableArray object
programatically?
The best way to get an object from a controller is to not get the
object.[1]
In MVC, controller objects are mediators between model objects and
view objects. View objects should be bound to controller objects and
controller objects should be bound to model objects. So chances are
that you're mixing the layers if you're trying to get an
NSMutableArray out of an NSArrayController.
Instead of getting the array from the array controller, you should
get the underlying observed collection property from your model
object and manipulate it. This is what the methods -
mutableArrayValueForKey: and -mutableSetValueForKey: are for
(depending on whether the collection you want to manipulate is an
array or a set). Any observers of the collection property -- such as
bound controllers -- will notice changes you make to the collection
and these changes will be propagated to bound views as appropriate.
-- Chris
[1] Just trying to come up with a memorable "hook"...
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden