简体   繁体   中英

Order of NSApplication delegate calls

I'm noticing something strange in my NSApplication delegate callbacks. When I start the app with debugger attached, I see what I expect: applicationDidFinishLaunching: is called first, then applicationDidBecomeActive:

When I run the app without the debugger, I get the calls in the order reversed: applicationDidBecomeActive: is called before applicationDidFinishLaunching:

Is there a reason for this? It makes it very confusing to account for different scenarios based on debugger vs. non-debugger.

[note: testing this is in Mavericks]

The relative order of those delegate methods during launch is not documented, so you should not rely on any particular order.

If you're concerned about some initialization not having been done when -applicationDidBecomeActive: is called, then you should do that initialization in -applicationWillFinishLaunching: rather than in -applicationDidFinishLaunching: . Alternatively, you should do the initialization on demand, such as initializing a property when its value is first requested.

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