I tried many ways but it seems I just cannot get it working.
// AppDelegate
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
true // false does not work either
}
// MainWC
func windowShouldClose(_ sender: NSWindow) -> Bool {
print(#function)
if sender === NSApp.mainWindow {
print("is main window")
sender.setIsVisible(false)
return false
}
return true
}
Once I hide the main window (using setIsVisible
or orderOut
) the app quits; even if I return false from applicationShouldTerminateAfterLastWindowClosed
, NSApp.mainWindow will become nil.