Rits
Rits

Reputation: 5175

Automatically instantiate singleton at launch

I have a singleton Session that I want instantiated at application launch. How do I do that?

I'm using this method of creating the singleton: http://cocoawithlove.com/2008/11/singletons-appdelegates-and-top-level.html

Upvotes: 1

Views: 358

Answers (2)

bioffe
bioffe

Reputation: 6393

In the first line of your didFinishLaunchingWithOptions method

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
 [YourSingletonClass class]; // ADD THIS LINE

it will trigger initialize method initialization in your singleton class

+ (void) initialize {
     _innerInstance = [[YourSingletonClass alloc] init];
}

Upvotes: 2

Eiko
Eiko

Reputation: 25632

If you access the singleton in the applicationDidFinishLaunching: method, they will should get set up.

Upvotes: 0

Related Questions