• 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: Cleaning up a singleton
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cleaning up a singleton


  • Subject: Re: Cleaning up a singleton
  • From: Andreas Mayer <email@hidden>
  • Date: Sat, 24 May 2008 09:48:49 +0200


Am 24.05.2008 um 09:28 Uhr schrieb Sebastian Nowicki:

I can't be certain that the cleanup function won't do other things in the future, such as removing files (locks).

If, for some other reason, you need to act when the application quits, you can register for the NSApplicationWillTerminateNotification notification.


Andreas

On 24/05/2008, at 2:24 PM, Andrew Merenbach wrote:

Hi,

Would the following NSApplication methods, placed into your application delegate's code, help at all?

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
- (void)applicationWillTerminate:(NSNotification *)aNotification;


Of the latter, the docs say that one should "Put any necessary cleanup code in this method."

Cheers,
	Andrew


I guess that would be the way to go. Although I'd have to either expose a method that wraps around the C function, or call the C function directly. Neither are really optimal, but the latter is a lot better than nothing.

In case you use the notification, there is no need to expose anything. You just register a method of your singleton to receive the NSApplicationWillTerminateNotification and do your cleanup there.


On Apple's developer website there are several example projects that make use of this. Here's one:

http://developer.apple.com/samplecode/CapabilitiesSample/listing5.html

You need only look at the -init and the -applicationWillTerminate: methods.


Andreas _______________________________________________

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: Cleaning up a singleton
      • From: Sebastian Nowicki <email@hidden>
References: 
 >Cleaning up a singleton (From: Sebastian Nowicki <email@hidden>)
 >Re: Cleaning up a singleton (From: Andrew Merenbach <email@hidden>)
 >Re: Cleaning up a singleton (From: Sebastian Nowicki <email@hidden>)

  • Prev by Date: Re: A documetation suggestion (was Re: Cocoa et al as HCI usability problem)
  • Next by Date: Re: Removing the Filename flag in Doc. based Application
  • Previous by thread: Re: Cleaning up a singleton
  • Next by thread: Re: Cleaning up a singleton
  • Index(es):
    • Date
    • Thread