• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: programatically quit a program
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: programatically quit a program


  • Subject: Re: programatically quit a program
  • From: Stéphane Sudre <email@hidden>
  • Date: Fri, 29 Aug 2008 12:08:17 +0200


On Aug 28, 2008, at 10:45 PM, Robert Claeson wrote:


On 28 Aug 2008, at 22:38, Wayne Shao wrote:

What is the correct way to quit a cocoa app? I could use C exit() but that
would loose the chance to invoke the right callbacks for clean up.
What is the call that would be equivalent to user explicitly selecting the
Quit from the menu.


I only found this

[[NSApplication sharedApplication] teminate:??];

But the terminate function takes an id for sender. What shall I use?

[[NSApplication sharedApplication] terminate:self]; works great. This is what I tend to use in smallish applications that don't need to do much else than simply terminate when asked to do so, and also terminate when the user closes the last window:


- (IBAction)terminate:(id)sender {
	[[NSApplication sharedApplication] terminate:self];
}

- (BOOL)applicationShouldTerminateAfterLastWindowClosed: (NSApplication *)theApplication {
return YES;
}


- (id)init {
	self = [super init];
	if (self != nil) {
		[[NSApplication sharedApplication] setDelegate:self];
	}
	return self;
}

Just in case:

to spare some electrons (at least for the source code), you can replace NSApplication sharedApplication] with NSApp.

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >programatically quit a program (From: "Wayne Shao" <email@hidden>)
 >Re: programatically quit a program (From: Robert Claeson <email@hidden>)

  • Prev by Date: Busy doing nothing
  • Next by Date: Convert unicode string into ascii
  • Previous by thread: Re: programatically quit a program
  • Next by thread: Re: programatically quit a program
  • Index(es):
    • Date
    • Thread