Thought I'd share my research on what workarounds might exist, in case that sparks any ideas.
In narrow cases (IBActions for the menu or toolbar items), the need for top-to-bottom data passing can be replaced with the responder chain. However, this won't help for other kinds of information, e.g. injecting a DownloaderService object into the view from the window, from the app delegate.
It looks like the new NSStoryBoard.instantiateInitialController(creator:) APIs introduced in 10.15 can remove the two-stage initialization pattern for NSWindowControllers. You're given the coder instance and expected to initialize the window controller yourself. This allows you to call any initializer you want. This is great, because you can make a MyWindowController.init?(coder: NSCoder, mySupplimentaryValues: ...). Since you're now calling a real init, the fields it sets no longer have to be implicitly unwrapped optionals. Sweet! Even still, I'm not sure how/when you would pass data from the window controller to the content view controller. aaaaand it appears to be total completely broken - https://stackoverflow.com/q/60343551/3141234, so I can't use it yet. Huge bummer :(
Segues are usually how you can pass data from one controller to another, but from what I can tell. This seems like a good point to "kick off" the top-down initialization process, but it appears that the containment segue between a window controller and its content view controller doesn't actually trigger a segue. Similarly, if you have a @IBSegueAction setup between an NSWindowController and an NSViewController, it will be ignored, as mentioned in the "known issues" section of the Xcode 11 release notes - https://developer.apple.com/documentation/xcode-release-notes/xcode-11-release-notes
I can give up on Storyboards and switch back to Nibs, where each window/view has its controller manually instantiated by code from its parent, allowing me to override init?(coder:) with init?(coder: NSCoder, mySupplimentaryValues: ...), where I can do all my work with all the values I need. I'm apprehensive to do this however, because I find it hard to believe that such a simple use case can't be implemented in Storyboards.
I can pass data from my App Delegate directly to my main window's content view controller using a global variable, or a singleton. yuck.
Topic:
UI Frameworks
SubTopic:
AppKit
Tags: