• 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: Automagic instantiation of singletons?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Automagic instantiation of singletons?


  • Subject: Re: Automagic instantiation of singletons?
  • From: Christian Brunschen <email@hidden>
  • Date: Fri, 18 Nov 2005 13:30:44 +0000


On 18 Nov 2005, at 13:26, Christian Brunschen wrote:


On 18 Nov 2005, at 12:47, Jonathan del Strother wrote:

Is there any way to persuade a singleton object to create itself? I have a few singleton objects that need to exist throughout the lifetime of the application, and am currently instantiating them in my application controller's applicationDidFinishLaunching: method.

It would be nice if I didn't have to explicitly do this. My initial thought was that you could do it through the singletons' + (void)initialize method - but of course, this isn't called at application startup - it's only called the first time you try and access the object, so it still needs to be manually set up.


Any other suggestions? I suspect it's not actually possible, but thought I'd throw it out to the obj-c gurus and see what they have to say...

The usual way is to have a class method through which you access the singleton, and in that class method you lazily create and initialize the singleton [ ... ]

And to follow up: If you need to guarantee the existence of the singleton at any specific time, you simply need to request it, and it will be created. If you need the singletons to be instantiated as soon as possible in the run of the application, doing so in '- applicationDidFinishLaunching:' may well be the right thing to do. otherwise, as soon as you reference them, they will be created.


Best wishes,

Jon

// Christian Brunschen

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Automagic instantiation of singletons? (From: Jonathan del Strother <email@hidden>)
 >Re: Automagic instantiation of singletons? (From: Christian Brunschen <email@hidden>)

  • Prev by Date: Re: Automagic instantiation of singletons?
  • Next by Date: URL loading system not threadsafe?
  • Previous by thread: Re: Automagic instantiation of singletons?
  • Next by thread: Re: Automagic instantiation of singletons?
  • Index(es):
    • Date
    • Thread