You could open a new thread. But I'll try to answer here first, with a sketch of solution.
What I do is declare a global var (in a singleton in fact) to hold the windowController.
myWindowController is of a subClass of NSWindowController, with its own nib.
In the subClass MyWindowController, I have several int:
class MyWindowController: NSWindowController, NSWindowDelegate {
override init(window: NSWindow!) {
// initialize what you need
super.init(window: window)
}
required init?(coder: (NSCoder?)) {
// initialize what you need
super.init(coder: coder!)
}
convenience init(someTag: Int) { // Need a parameter to differentiate from basic init()
self.init(windowNibName: NSNib.Name(rawValue: "MyNibName")) // NibName of the window
// initialize what you need
}
}
The global var is initialized (in singleton) with:
myWindowController = MyWindowController(someTag: 0) // in fact GlobalData.sharedGlobal.myWindowController =
Then the IBAction of menuItem is simply:
@IBAction fileprivate func showMyWindow(_ sender: NSMenuItem) {
myWindowController!.showWindow(self) // in fact, GlobalData.sharedGlobal.myWindowController!.showWindow(self)
}
Hope that helps.