I have opened my window in the traditional way, but I want to run some code when the window is closed by clicking the close box (red button). Is there a good way of doing this?
func openMyWindow()
{
myWindow = (NSWindow(
contentRect: NSRect(x: 100, y: 100, width: 100, height: 600),
styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
backing: .buffered, defer: false))
myWindow!.contentView = NSHostingView(rootView: MyWindowView())
myWindow!.makeKeyAndOrderFront(nil)
}