Re: Sharing a model
Re: Sharing a model
- Subject: Re: Sharing a model
- From: Kyle Sluder <email@hidden>
- Date: Tue, 15 Feb 2011 10:49:16 -0800
On Feb 15, 2011, at 8:50 AM, Marc Respass <email@hidden> wrote:
> Keep in mind that in an NSDocument-based application, your NSDocument subclass *is* the model. You can have multiple windows all looking at the same model. You can get the document from the window's controller and the window from any view in the window. If your custom view is controlled by an NSViewController then from the view controller,
Apple's documentation makes reference to NSDocument as a "model controller." Its purpose is to encapsulate your document's model objects, read and write them from disk/pasteboard/storage, and manage the view/window controllers that dictate te behavior of your UI.
Your actual model objects are conceptually referenced by the NSDocument subclass. For a simple document, this might be an NSArray of NSDictionaries, or a single NSTextStorage. Most applications will have custom NSObject subclasses for their model objects, like Books or Employees.
But if you think about it this way, NSDocument's role becomes a bit clearer. It is the place that all the view and window controllers go to in order to get at the set of model objects. That description fits the definition of a controller quite well, so it's fair to say that NSDocument is a controller. It just sits on the other side of a logical division between "model stuff" and "view stuff."
--Kyle Sluder
>
> id model = [(MyDocument *)[[[[self view] window] windowController] document] model];
>
> Although I don't recommend that in regular use, there is a connection. The default project for an NSDocument-based app hides the fact that the document is the model and the window is simply a view into the model. Setting up to use more than one window exposes it but it's a really cool feature. You might want your graphic view in another window or in a floating window and it'll all be tied in to the same underlying model.
>
> Marc
> _______________________________________________
>
> 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
_______________________________________________
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