Teo Choong Ping
Teo Choong Ping

Reputation: 12808

How to properly quit application, call exit(0)?

I'm not sure which is the right way, right now I'm just calling exit(0) when a user clicks on the exit button.

Upvotes: 5

Views: 6052

Answers (3)

C. S.
C. S.

Reputation: 103

The previously given answer is deprecated since 10.10 and this question is the first thing that turns up for cocoa quit application, so use this instead (Swift):

NSApplication.sharedApplication().terminate(self)

Note: As of now it's the following:

NSApplication.shared().terminate(self)

Upvotes: 6

d00dle
d00dle

Reputation: 1316

I always terminate App the safe way.

[NSApp performSelector:@selector(terminate:) withObject:nil afterDelay:0.0];

This will put the event in the next loop.

Upvotes: 0

mipadi
mipadi

Reputation: 410662

Use NSApplication's terminate method. For example:

[NSApp terminate:self]

Documentation is available here.

Upvotes: 24

Related Questions