• 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: applicationWillTerminate: issue
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: applicationWillTerminate: issue


  • Subject: Re: applicationWillTerminate: issue
  • From: Jason Foreman <email@hidden>
  • Date: Tue, 25 Aug 2009 10:46:43 -0500


On Aug 24, 2009, at 10:26 PM, Michael de Haan wrote:

-applicationWillTerminate: doesn't magically get called.
NSApplication posts this notification to the default notification
center.  NSApplication also automatically signs its delegate up for
this notification.


Kyle, from the "Cocoa Fundamentals Guide": "Although you can dynamically change the delegate, only one object can be a delegate at a time. Thus if you want multiple objects to be informed of a particular program event at the same time, you cannot use delegation."

So, if I understand you and the documentation correctly , even though I had implemented the delegate of NSApplication in **both** of my classes, **only** one of those classes will respond to "applicationWillTerminate:" at a time. If this is indeed correct, then I need to rethink the design of my application, and you have already suggested how to do this.



True, only one object can be the application delegate at any one time. However, multiple objects can be subscribed to application notifications, and the notification will be sent to all subscribed objects when it is posted.


You should read up on NSNotificationCenter, and on the notifications that NSApplication posts, specifically NSApplicationWillTerminateNotification in your case. Your second object should not set itself as the application delegate, but rather should subscribe to this notification and handle it accordingly.


Jason


Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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

  • Follow-Ups:
    • Re: applicationWillTerminate: issue
      • From: Michael de Haan <email@hidden>
References: 
 >applicationWillTerminate: issue (From: Michael de Haan <email@hidden>)
 >Re: applicationWillTerminate: issue (From: Kyle Sluder <email@hidden>)
 >Re: applicationWillTerminate: issue (From: Michael de Haan <email@hidden>)

  • Prev by Date: Re: NSTableView and programmatic changing of contextual menu
  • Next by Date: Re: NSTableView and programmatic changing of contextual menu
  • Previous by thread: Re: applicationWillTerminate: issue
  • Next by thread: Re: applicationWillTerminate: issue
  • Index(es):
    • Date
    • Thread