Hi, How can I release my NSWindow manually? when the user tap on red close button?
@objc func windowWillClose() {
// Handle the window closing event here
// You can perform any necessary cleanup or ask the user for confirmation
// Return true to allow the window to close
_window?.contentViewController = nil
_window?.delegate = nil
_window = nil
NotificationCenter.default.removeObserver(self, name: NSWindow.willCloseNotification, object: nil)
}
//Settings cell tap
@objc func settingsItemClicked () {
//_window:NSWindow?
NotificationCenter.default.addObserver(self, selector: #selector(windowWillClose), name: NSWindow.willCloseNotification, object:_window)
if _window?.isVisible == false {
// Load the view controller from the storyboard
let storyboard = NSStoryboard(name: "Main", bundle: nil)
guard let ViewController = storyboard.instantiateController(withIdentifier: "SettingsViewController") as? SettingsViewController else {
fatalError("Unable to instantiate SettingsViewController from storyboard.")
}
// _window.delegate = self
// Set the view controller as the content view controller of the window
_window?.contentViewController = ViewController
_window?.isReleasedWhenClosed = false
_window?.hidesOnDeactivate = true
// Set the window's title
_window?.title = "DynamicLake"
// Show the window
_window?.makeKeyAndOrderFront(self)
}else{
print("The settings view is already open")
}
}