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:)
, which is a new function as of MacOS 10.15. The block of code in question is:
let mainWC = storyboard.instantiateController(identifier: "id") { 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 the trivial initializer:
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.
NSStoryboard.instantiateController(identifier:creator:)
,NSStoryboard.instantiateController(identifier:)
orNSStoryboard.instantiateInitialController(creator:)
? – StoolNSStoryboard.instantiateInitialController(creator:)
. – Stool