I've found a case where some of my view controllers' initWithCoder methods are invoked before the application didFinishLaunching method in the application delegate. (I've confirmed this by setting breakpoints and looking at the sequence of invocations)
I'm using a storyboard. A UITabBarController is the initial view controller. Part of the problem is that the storyboard creates objects in an unknown order; perhaps it's creating the view controllers before the app is done launching.
In any case, the problem is that I'm registering initial user defaults. This must happen before any piece of the program looks at them. So, I'm trying to find the spot where the registering code will be guaranteed to execute first.
Is there any such place?
Note: This thread discusses it a little, but there isn't really a conclusion...
ViewDidLoad runs before AppDelegate didFinishLaunchingWithOptions gets executed!
The standard means of initializing user defaults is in a "+(void)initialize" method in your app delegate:
+ (void)initialize
{
if(self == [MyAppDelegate class]) {
...
}
}
This is guaranteed to run before any delegate method gets messaged.
PS: I instantiate a whole bunch of viewControllers in my didLaunch method before returning from that method.