Search code examples
objective-cmacoscocoanswindowcontrollernsviewcontroller

Mac OS X Cocoa single window application architecture


I cannot understand how to design an application in optimal way for a single window application to work in Mac OS X. I would prefer a single document - single window application (I'm not coding a utility application), but it is not clear where should I initialize a window content.

On iOS I should use -[UIViewController viewDidLoad] or -[UIViewController viewWillAppear:] method of a root view controller for that purpose.

Could you please advice me any tutorial or explain how to deal with NSDocument - NSDocumentController - NSWindowController - NSViewController classes?

Thanks for your answers. :-)


Solution

  • You could put your window logic into your AppDelegate, but I discourage it. I recommend doing your own separate NSWindowController subclass to control the window, even for a single-window app. It's a very nice separation.

    I don't see why one would want to use NSDocumentController for a single-window app. NSViewController is meant to control your custom views. It's usually not used in the average simple Mac app, unless you have some custom views you want to control specially.

    So, in your AppDelegate's, say, applicationDidFinishLaunching:, you would allocate and initialize the window controller and show the window.

    There is a good chapter in "Cocoa Programming for Mac OS X" by Hillegass on how to work with window controllers. Apple's docs also have some material on it, of course.