Re: Question about NSArrayController
Re: Question about NSArrayController
- Subject: Re: Question about NSArrayController
- From: Chris Hanson <email@hidden>
- Date: Mon, 4 Jun 2007 00:59:21 -0700
On Jun 3, 2007, at 11:14 PM, Matthew Delves wrote:
I'm beginning to play around with cocoa and have some data stored in
an NSArrayController object.
Stop, and take the time to understand the Model-View-Controller
architecture and how it's implemented in Cocoa.
In one of your replies to Malcolm, you stated that you learn best by
jumping in feet-first. However, in this case, you really would best
learn to walk before you try to run. If you don't, you'll have a
whole lot more frustrating experience than if you try to follow the
well-defined learning path for Cocoa. That path goes, roughly:
* Objective-C and OOP basics, including memory management
* The Model-View-Controller architecture
* NSControl and the target/action pattern
* NSTableView and the data source & delegation patterns
* Key-Value Coding
* Key-Value Observing
* Cocoa bindings
* Core Data
If you follow the above path, one topic leads naturally into another
and you'll get a comprehensive picture of not only how everything fits
together in Cocoa but *why* it fits together the way it does. It
won't take very much time to follow the path, and at the end of it
you'll be able to move much more quickly than if you try to skip
ahead. If you do try to skip ahead to the very end without
understanding the basics, it'll be like trying to do calculus-based
physics without actually knowing any calculus: You might be able to
crank the formulae using a calculator, but you'll have no idea what
the results you're getting mean or how to debug them when they're
telling you something obviously wrong.
All of that said, from an MVC perspective, the NSArrayController
should be mediating access between your model-level objects and your
view-level objects; it should not be used for "storage" -- that's what
your model-level objects are for.
*Completely ignore* the fact that you can create nibware demos without
any code that "store" their data "in" the NSArrayController; this is
only an acceptable pattern for nibware demos, and should be avoided in
production code.
I've been able to insert the data programmatically into the
NSArrayController, though am having problems getting the data from
an instance of the class.
Is it possible to obtain an enumerator for the NSArrayController?
What is the best way to access that information?
Don't go through the NSArrayController to manipulate your model-level
objects, except from view-level code.
Instead, implement the model-level object that has the collection of
data you're presenting to be compliant with the needs of Key-Value
Coding and Key-Value Observing, you can just bind your
NSArrayController to it. Then just use the appropriate accessor
methods to make modifications to it those model-level objects, and the
changes will be reflected appropriately in your views.
-- Chris
-- MVC curmudgeon
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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