方法调配 - 如何确保方法在调用之前进行调配
我正在使用 SIMBL 方法调配第三方应用程序创建 NSMenuItems,但 50/50 的时间菜单项是在我的方法调配初始化之前创建的。
有什么干净的方法可以确保我的搅拌始终是第一位的?我想我可以调整 applicationDidFinishLaunching: 并在那里继续我的调整。但我担心我会在那里遇到同样的错误,在我的实际 swizzle 到位之前将调用 applicationDidFinishLaunching 。
约翰
I'm method swizzling a third party applications creation of NSMenuItems with SIMBL, but 50/50 of the time the menu-items are created before my method swizzling is initialized.
What is a clean way to make sure my swizzling always comes first? I guess I could swizzle applicationDidFinishLaunching: and continue my swizzling there. But I'm afraid I'm going to run in to the same error there, where applicationDidFinishLaunching will be called before my actual swizzle is in place.
John
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您希望在加载库后立即进行混合。您可以通过
+initialize
、+load
或构造函数来完成此操作。@bbum 的对此问题的回答提供了更多信息,以及他的一篇博客文章使用这些特殊类方法的注意事项。
(我故意不质疑你所做的事情是否明智;))
You'd want the swizzle to happen as soon as the libraries are loaded. You can do that via
+initialize
,+load
, or a constructor function.@bbum's answer to this question has a bit more information, along with one of his blog posts on the caveats of using these special class methods.
(And I'm purposely not questioning the wisdom of what you're doing ;) )
您可以像这样使用构造函数:
来自 GCC 文档:
注意:虽然这最初来自于
GCC
,但它也适用于LLVM
。You can use constructor functions like this:
From GCC documentation:
Note: Although this is originally from
GCC
, it also works inLLVM
.