iOS to macOS developer

Hi guys, I need to understand the best macOS development approach.

Currently I am an iOS Developer, I have some doubts about the relationship between:


  • NSWindowController
  • NSWindow
  • NSViewController


I seem to have understood that NSWindowController is used in case of Document based app,

so, if I have to develop a single window app with a with a secondary "Inspector "window, the most

correct approach is to manage everything simply with a NSWindow -> NSViewController relationship

for both windows?


The doubt comes to me from the moment that NSStoryboard makes a forced use of NSWindowController

for every single window to manage. 😅

Replies

I have an app which is not document based and use NSWindowController extensively.


For inspector window (like in XCode), HUD panel are really convenient.

    @IBOutlet fileprivate weak var hudInspector : NSPanel! // Non visible at launch

Because you can have multiple windows, multiple types of windows, window behaviors such as opening, closing, resizing, moving, etc., window controllers are used to implement and effect those behaviors. Windows are the main vessels for views and view behaviors in MacOS. Simple applications can have a window controller and a window with button, label, text views, string field views, etc., directly implemented in the window, with the window and/or window controller interacting with the model. Windows can contain a view controller that manages the views for that window, which is where the iOS experience begins to parallel the MacOS experience.


These relationships hold whether or not documents are involved. Document-based applications layer onto these relationships by interweaving documents and document controllers.


More questions are welcome.

I'm primarily a Mac developer. Here is my typical use of those classes:

NSWindowController - Apple boilerplate comments in the NSDocument template source files. I do some document setup in windowControllerDidLoadNib, but I never actually use the passed in windowController. This is just the only place to do document setup.


NSWindow - I create most NSWindows via IB. I do interact with them a little bit. I think mainly my interaction is listening for notifications to update appearance. I also use them for managing parts of the NSDocument lifecycle that are otherwise completely missing. My app is a bit unusual because I do some programmatic animation of NSWindow. It feels like 1995 all over again.


NSViewController - NSViewController is a new class designed specifically to make iOS developers feel at home. Unfortunately, all it really does on the Mac is add an entirely new, redundant layer of complexity. I've never used it, or storyboards on the Mac, for that matter. I never click the "Use Storyboard" checkbox when creating a new project.