I used the following code to make it reopen and prevent from closing when you click on the close button.
The problem is that it just closes(the dot under the app's icon in dock disappears)
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return false
}
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
for window in NSApplication.shared.windows {
window.makeKeyAndOrderFront(self)
}
return true
}
UPDATE
When I keep the main window open the app icon doesn't disappear from dock.