开发者

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


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];
}


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜