swiftUI how to Hide window instead of closing it when click the close button on MacOS.
swiftUI how to Hide window instead of closing it when click the close button on MacOS
Add a Comment
swiftUI how to Hide window instead of closing it when click the close button on MacOS.
after all i find solution.
first AppDelegate implement NSWindowDelegate then catch you main window in applicationDidFinishLaunching, then point mainWindow.delegate = self
func applicationDidFinishLaunching(_ notification: Notification) {
mainWindow = NSApp.windows[0]
mainWindow!.delegate = self
setUpMacMenu()
func windowShouldClose(_ sender: NSWindow) -> Bool {
NSApp.hide(nil)
return false
}
}```
after all i find solution.
first AppDelegate implement NSWindowDelegate then catch you main window in applicationDidFinishLaunching, then point mainWindow.delegate = self
func applicationDidFinishLaunching(_ notification: Notification) {
mainWindow = NSApp.windows[0]
mainWindow!.delegate = self
setUpMacMenu()
func windowShouldClose(_ sender: NSWindow) -> Bool {
NSApp.hide(nil)
return false
}
}```