Call to open Storyboard ViewController cashes app

Hello:


I am trying to open a Storyboard View from an @IBAction but the app crashes with no log output. Any help will be appreciated.

Below is the code. Lines 10 to 18 are highlighted in the code when the crash occurs.


@IBActionfunc launchMainMenu(_ sender: NSMenuItem) {
         if ((mainWindowController) == nil){
             var windowController : NSWindowController?
             let storyboard = NSStoryboard()
       

                func openMyWindow()
                {
                
                 if let vc = storyboard.instantiateController(withIdentifier: "4554") as? ViewController
                        {
                         let myWindow = NSWindow(contentViewController: vc)
                            myWindow.makeKeyAndOrderFront(self)
                            let controller = NSWindowController(window: myWindow)

                            controller.showWindow(self)

                        }
                
                    }
              openMyWindow()
         }
       
    }
Answered by Claude31 in 411814022

Your instantiation of storyboard is wrong: you instantiate an empty storyboard.

Change as

        let storyboard = NSStoryboard(name: "Main", bundle: nil)
Accepted Answer

Your instantiation of storyboard is wrong: you instantiate an empty storyboard.

Change as

        let storyboard = NSStoryboard(name: "Main", bundle: nil)
Call to open Storyboard ViewController cashes app
 
 
Q