Re: NSDocument and NSViewControllers
Re: NSDocument and NSViewControllers
- Subject: Re: NSDocument and NSViewControllers
- From: Quincey Morris <email@hidden>
- Date: Sat, 05 Dec 2015 12:40:41 -0800
- Feedback-id: 167118m:167118agrif8a:167118sBiVHpxBZZ:SMTPCORP
On Dec 5, 2015, at 12:20 , Rick Mann <email@hidden> wrote:
>
> I'll probably make the document a delegate of the view controller so it can be informed of changes to the model.
This may not apply to your app, but what I usually end up doing in an app of any complexity is have (essentially) two data models. The “real” one belongs to the document. Then there’s a “derived” data model (usually in the window controller in the past, but possibly in the new, enhanced view controllers in the future) which rearranges the document data model suitably for the particular UI that the particular window UI finds convenient.
This is kind of duplicate effort (though not duplicate data, mostly, because the “derived” data model really is only a wrapper around the real one), but it tends to simplify the UI code a lot. For example, if the real data model is flat but the UI displays the data hierarchically, it may be easier to have an outline view connected to a hierarchical data structure. Or if data model values need to be transformed into displayable strings in customizable ways, it can be done in the derived data model.
Or (and this can be a fairly important issue) undo groupings are really structured by the UI, even though undo actions are associated with the document. It often makes more sense to have the window controller decide how to package (and how to name) undoable sequences, rather than leaving it to the granularity of document model property updates.
_______________________________________________
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