Pedro Vieira
Pedro Vieira

Reputation: 3370

How to prevent NSWindow from closing on the windowWillClose method?

How can I prevent my NSWindow from being closed when the windowWillClose method is called?

Upvotes: 0

Views: 2036

Answers (2)

Vicente Garcia
Vicente Garcia

Reputation: 6370

Swift example:

You need to set the delegate of the NSWindow and implement NSWindowDelegate

func windowShouldClose(_ sender: NSWindow) -> Bool {
     return false
}

Upvotes: 0

Tom Dalling
Tom Dalling

Reputation: 24125

You can't. By the time windowWillClose: is called, it is too late. You need to stop it before this point with windowShouldClose:.

Upvotes: 5

Related Questions