I want to restore a window position of my Cocoa app whenever an user launches the app. This feature is implemented in default in Cocoa. However, I also want to make my app terminated by tapping the red x
button on the top-left corner on the toolbar, so I wrote the following in AppDelegate.swift
:
func applicationShouldTerminateAfterLastWindowClosed(sender: NSApplication) -> Bool {
return true
}
This makes the app quit immediately by tapping the red x
button. However, if you terminate the app in this way, the window doesn't restore to the previous state the next time you open the app.
Why does the app not restore when you terminate the app by closing the window? And how can I restore even if the user terminates the app by closing the window?