Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is NSApp terminate:id deprecated?

I have been searching for how to terminate my application programmatically. I found in many topics people using NSApp terminate:id.

In Xcode terminate:id is crossed. Is this method deprecated ? Should I use it to terminate my application ? If no which is the right way to do it ?

Update: Picture of what i mean when I say that it's crossed: enter image description here

like image 329
George Sofianos Avatar asked Apr 06 '13 16:04

George Sofianos


2 Answers

I don't see that terminate is deprecated. A possible cause for the compiler warning might be that in

[NSApp terminate:sender]

NSApp returns a general id, so that the compiler does not know which terminate message is actually meant. An indeed, if I use "Jump to Definition", Xcode jumps to

@protocol NSInputServiceProvider
...
- (void) terminate:(id)sender NS_DEPRECATED_MAC(10_0, 10_6);

But if you use the equivalent code

[[NSApplication sharedApplication] terminate:sender];

then the compiler warning goes away.

like image 131
Martin R Avatar answered Nov 19 '22 03:11

Martin R


Nope, not deprecated:


terminate:

Terminates the receiver.

- (void)terminate:(id)sender

Parameters

sender

Typically, this parameter contains the object that initiated the termination request.

Discussion

This method is typically invoked when the user chooses Quit or Exit from the application’s menu.

When invoked, this method performs several steps to process the termination request. First, it asks the application’s document controller (if one exists) to save any unsaved changes in its documents. During this process, the document controller can cancel termination in response to input from the user. If the document controller does not cancel the operation, this method then calls the delegate’s applicationShouldTerminate: method. If applicationShouldTerminate: returns NSTerminateCancel, the termination process is aborted and control is handed back to the main event loop. If the method returns NSTerminateLater, the application runs its run loop in the NSModalPanelRunLoopMode mode until the replyToApplicationShouldTerminate: method is called with the value YES or NO. If the applicationShouldTerminate: method returns NSTerminateNow, this method posts a NSApplicationWillTerminateNotification notification to the default notification center.

Do not bother to put final cleanup code in your application’s main() function—it will never be executed. If cleanup is necessary, perform that cleanup in the delegate’s applicationWillTerminate: method.

Availability

Available in OS X v10.0 and later.

See Also

  • – run
  • – stop:
  • – applicationShouldTerminate: (NSApplicationDelegate)
  • – applicationWillTerminate: (NSApplicationDelegate)
  • – replyToApplicationShouldTerminate:
  • NSApplicationWillTerminateNotification

Related Sample Code

  • BlastApp
  • PreLoginAgents

Declared In

NSApplication.h

like image 37
Dave DeLong Avatar answered Nov 19 '22 02:11

Dave DeLong