开发者

Automatically instantiate singleton at launch

开发者 https://www.devze.com 2023-01-28 05:51 出处:网络
开发者_开发技巧I have a singleton Session that I want instantiated at application launch. How do I do that?
开发者_开发技巧

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

精彩评论

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