So....NSWindowController or NSWindow?


If one wanted to rely on the XIB IB method of creating windows, which would be the preferred means of creating and managing windows?

NSWindow / NSView?


NSWindowController / NSViewController?

The code appears to be similar, but I’m a little worried about the NSDocument getting involved on the Controller side.


You almost always want to use at least NSWindowController. This is a key part of Model-View-Controller: rely on your controllers to glue your GUI objects together, and to the model itself. In most non-trivial applications NSViewController is going to be a very useful way to subdivide the controller responsibilities for an application. You are going to have a view hierarchy of some sort, but you always want to have controllers supporting that.

Consider Xcode. It almost certainly has an NSWindowController, and then each of the inspectors is likely an NSViewController. I would even bet that most inspectors are composed of multiple NSViewControllers stacked together.

As for documents and controllers, in simpler apps the NSDocument can act as the window controller; this is how we use it in the book. In more advanced apps, you will want to create an NSWindowController, and connect it to the NSDocument. This is a bit beyond the scope of a beginner Cocoa book, but the place to do this (and a good starting point for learning more about it) is NSDocument’s -makeWindowControllers. This is discussed in the Cocoa documentation.

If you’re getting all of this, great, but if you’re not, start small and work your way up. It can be pretty daunting to apply these design concepts when you’re starting out.


Wow, what a great response. I really appreciate the investment.

The MVC is very familiar to me, and theoretically Apple’s explanation is very straight forward. I think the challenge I’ve found is OUTSIDE the iOS device. On an iPhone I just hook up my Views and watch them dominate the screen exclusively for the most part. In OSX proper the concept is a bit blurry on the specifics of how to place multiple views within a single NSWindowController. So far I think my best bet is to use a BOX object to handle most of the game play field, and add alternate dialogs into the super NSWindow object as a layer on top of the view.

I have the SourceView project out of the Apple Docs open, and it appears to have some basic MVC implementations displayed, but as you might imagine, nothing with multiple views in a single window object. I will say this much, there is yet to be a single book published that addresses this essential framework outside of very basic app designs. One is left with documentation from Apple that always covers the basics well, but leaves one to experiment or sift through code to find a tiny morsel of what you’re really looking for.

O’well, such as life. :slight_smile: