[英]Order of NSApplication delegate calls
I'm noticing something strange in my NSApplication delegate callbacks. 我在NSApplication委托回调中注意到一些奇怪的事情。 When I start the app with debugger attached, I see what I expect:
applicationDidFinishLaunching:
is called first, then applicationDidBecomeActive:
当我开始调试应用程序连接,我看到预期的结果:
applicationDidFinishLaunching:
首先调用,然后applicationDidBecomeActive:
When I run the app without the debugger, I get the calls in the order reversed: applicationDidBecomeActive:
is called before applicationDidFinishLaunching:
在没有调试器的情况下运行应用程序时,我得到的调用顺序相反:
applicationDidBecomeActive:
之前调用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] [注意:在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:
. 如果您担心在调用
-applicationDidBecomeActive:
时尚未完成某些初始化,则应在-applicationWillFinishLaunching:
而不是在-applicationDidFinishLaunching:
中进行初始化。 Alternatively, you should do the initialization on demand, such as initializing a property when its value is first requested. 另外,您应该按需进行初始化,例如在首次请求属性值时初始化属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.