Search code examples
swiftmacosmacos-sierra

Swift mac app -> Moving cursor closes NSWindow


I am new MAC application development using swift. I have a NSViewController with different menu options.

In which, I have one NSWindow open already and tapping "Window" menu option, opening another window.

let passwordVC = PasswordViewController()
        let pwdWindow = NSWindow(contentViewController: passwordVC)
        pwdWindow.title = "Password"
        pwdWindow.orderFront(self)
        let controller = NSWindowController(window: pwdWindow)

        controller.showWindow(self)

but it closes automatically when I start moving cursor. I am doing nothing, it stays. I am not sure what is the issue. Kindly help.


Solution

  • I am using like this. And it works for me. Seems to be an alternate way.

     let passwordVC = PasswordViewController()
            let pwdWindow = NSWindow(contentViewController: passwordVC)
            pwdWindow.title = "Password"
            let application = NSApplication.shared()
            application.runModal(for: pwdWindow)