Storyboard custom instantiated window controller

I am getting what feels like a bug when trying to custom instantiate a window controller from a storyboard. I am using NSStoryboard.instantiateController(identifier: creator: ). The block of code in question is:

let mainWindowController = storyboard.instantiateController(identifier: "Analysis Window Controller") { aDecoder in
                MainWindowController(coder: aDecoder)
            }


I have SUCCESSFULLY used basically this exact code for custom instantiating the main view controller, and just assigning that view to a new window and a new window controller. That works fine. I can also instantiate the window controller the old fashioned way without custom initialization with instantiateController(identifier:). But when I try the above code for custom instantiation of the window controller I end up with the following error:


Assertion failure in -[NSClassSwapper _createControllerForCreator:coder:]...Custom instantiated controller must call -[super initWithCoder:]


Note that both my custom view controller class (which works) and my custom window controller class MainWindowController (which doesn't work) have implemented:

    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }


I know that this functionality is new as of OS 10.15, but the documentation says it should work for window controllers AND view controllers, and the error message does not make any sense to me. https://developer.apple.com/documentation/appkit/nsstoryboard/3203780-instantiateinitialcontroller

What is here the purpose of

{ aDecoder in MainWindowController(coder: aDecoder) }


I looked at this:

h ttps://gist.github.com/sgr-ksmt/fc5631dd92701b0464e7b17e3df544fe

They explain:

You can now invoke a custom initializer from a creation block that's passed through

instantiateInitialViewController(creator:)
or
instantiateViewController(identifier:creator:)
. This makes it possible for you to initialize view controllers with additional context and arguments, while taking advantage of defining them in a storyboard through Interface Builder. A custom controller initializer must call its
super.init(coder:)
method and pass the coder argument that it receives through the creation block. (48313869)


What I understand is that super.init(coder:) must be called from the init, not only from init(coder:).

The { aDecoder in MainWindowController(coder: aDecoder) } is the custom initializer/creator block. This is the most trivial I can make it. The verbose way to write the function would be:

instantiateViewController(identifier: anIdentifier,creator: { (aDecoder: NSCoder) -> MainWindowController in
     MainWindowController(coder: aDecoder})

I can't just call super.init(coder:) from the Window Controller's init, because I need the storyboard to pass the coder. And like I said, my current setup produces the expected behavior when I use it to instantiate the view controller. It is only when I try to make a window controller that I run into issues.

I have this exact same bug / bad error message when I try to use a creator block to make an NSWindowController. Someone screwed up.


-Wil

This is filed as Feedback #FB7626059


"`NSStoryBoard` `instantiateInitialController(creator:_)` crashes when trying to create an `NSWindowController`"

(deleted)

Storyboard custom instantiated window controller
 
 
Q