7cows
7cows

Reputation: 5044

Order of awakeFromNib, applicationWillFinishLaunching, and applicationDidFinishLaunching?

Assume a default Xcode Cocoa app template where the App Delegate is in the main XIB file.

Of course, applicationWillFinishLaunching: is called before applicationDidFinishLaunching:.

Why is awakeFromNib being called before applicationWillFinishLaunching:?

The docs for applicationWillFinishLaunching: say this:

Sent by the default notification center immediately before the application object is initialized.

Why does this not contradict awakeFromNib being called before applicationWillFinishLaunching:?

Can I rely on this order?

Upvotes: 3

Views: 2202

Answers (3)

Sangram Shivankar
Sangram Shivankar

Reputation: 3573

1. awakeFromNib
2. applicationWillFinishLaunching
3. applicationDidFinishLaunching

  • the awakeFromNib will be called first.
  • When the nib file has been initialized, each object referenced in the nib will be looped through and they will all receive an awakeFromNib call if they respond to the message.
  • After all of that is done then the Application’s delegate will receive the applicationDidFinishLaunching: call. This is the notice that everything is loaded and that the application is ready to start receiving user input.

Upvotes: 1

Mike Lischke
Mike Lischke

Reputation: 53502

The order is awakeFromNib, applicationWillFinishLaunching and applicationDidFinishLaunching, which makes sense, given that you first need to load the UI before you can actually run the application. The notification is not applicationDidStartLaunching which one could see as something that has to go before awakeFromNib.

Upvotes: 5

Jeff
Jeff

Reputation: 12183

According to this answer, awakeFromNib is called when the controller is being extracted from the nib archive. I suppose that is happening after the application has finished launching.

Upvotes: 0

Related Questions