I have a sample project as:
https://github.com/ericgorr/nspanel_show.git
My project is a storyboard, document based application. I would like to use a custom segue to toggle the visible state of the inspector window. What I have should work, but I cannot quite determine how to make the inspector window a singleton.
I believe I should start with:
class InspectorWindowController: NSWindowController
{
static let sharedInstance = InspectorWindowController()
// override func init()
// {
//
// }
override func windowDidLoad()
{
super.windowDidLoad()
NSLog( ":::: %@", InspectorWindowController.sharedInstance );
}
}
But exactly what the initialization should look like in my situation is escaping me, especially since the window is inside of a storyboard.
Here's how I would modify your code:
Main.storyboardgive your InspectorWindowController an identifier, such as "Inspector Window Controller"In
InspectorWindowController, implement your singleton as follows:In
Main.storyboarddelete the segue fromWindowControllertoInspectorWindowControllerIn
WindowControllerreplace theshowMyPanel()andhideMyPanel()IBActions with:Also in
WindowController, remove theNSLog()call fromwindowDidLoad(). It causes a recursive call to theInspectorWindowController.sharedinitialization code.Main.storyboardlink the Inspector toolbar button totoggleInspectorPanel()The
InspectorWindowController.sharedsingleton will be initialized, and the inspector panel loaded (but not shown), the first time it is referenced.