I am trying with no success to use instantiateController(identifier: creator:)
to create a window controller.
Here is the code :
class MyOwnWindowController: NSWindowController {
required init?(coder: NSCoder) {
super.init(coder: coder)
}
}
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ aNotification: Notification) {
let storyboard = NSStoryboard(name: NSStoryboard.Name("Main"),
bundle: nil)
let sceneIdentifier = NSStoryboard.SceneIdentifier("main-window-controller")
let windowController = storyboard.instantiateController(identifier: sceneIdentifier,
creator: { coder in
MyOwnWindowController.init(coder: coder)
})
windowController.showWindow(self)
}
}
Of course, I have a storyboard with a window controller scene with id "main-window-controller" (and of class MyOwnWindowController
).
The run crashes inside the instantiateController method. I can see that my init(coder:) method is correctly called. The following message is printed in the console :
2020-04-18 09:38:33.307506+0200 TestApp[1880:43088] *** Assertion failure in -[NSClassSwapper _createControllerForCreator:coder:], /AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1894.40.150/IB.subproj/NSClassSwapper.m:182
2020-04-18 09:38:33.307724+0200 TestApp[1880:43088] Custom instantiated controller must call -[super initWithCoder:]
And it is obvious that [super initWithCoder:] is called...
I have tried in Swift and Objective-C, and I get the same result.
So how to use instantiateController(identifier: creator:)
?