简体   繁体   中英

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?

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM