Search code examples
objective-ciosviewdidload

iOS function to be called once (when application is initialized)


I have an iOS application. Application has 2 different views: Main and Settings. In fact, application needs to load and initialize some library and framework before it is used in Main View.

When I put this initialization in viewDidLoad method, it works OK. But when go to Settings and come back to Main View, initialization starts again, which is not what I want, and application results in a memory problem.

I need an method that is called once when application is started. Any idea?

EDIT: I switched to tabbed view. It loads views once. This is another solution.


Solution

  • Use this one:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    

    It should be in your appdelegate class.

    Hope it helps