cocoa 插件中重复的冲突框架
我目前正在为我的应用程序编写一个插件框架。我希望能够发布插件而无需更新我的应用程序,并且我打算使该框架可用于第三方插件。当两个插件附带相同的框架时,我目前遇到了问题。当插件加载时,运行时会变得混乱,因为框架被加载了两次。缓解这个问题的最佳方法是什么?
I am currently writing a plug-in framework for my application. I would like to be able to release plugins without having to update my application, and I intend on making the framework available for third party plugins. I am currently running into issues when two plugins ship with identical frameworks. When the plugins are loaded the runtime gets confused because the framework gets loaded twice. What is the best way to mitigate this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有点不清楚你在问什么。您的意思是这些插件都包含您的框架或其他第三方框架?
如果它们都包含您的框架,那么您不应该这样做;他们应该引用嵌入在您的应用程序中的框架。您可以通过
@executable_path
引用框架包,因此它与您的应用程序相关(例如@executable_path/../Frameworks/MyFramework.framework/
)。这是来自 Lightroom 的示例:
如果它们都包含其他第三方 Objective-C 框架,则这是插件中的错误; Objective-C 运行时没有命名空间,当您加载多个同名的类时,您不能期望得到任何正常的响应。 这个问题对此进行了讨论,它提供了几种针对 ObjC 命名空间冲突的解决方法。
It's a bit unclear what you're asking. Do you mean that the plugins both include your framework, or other third-party frameworks?
If they both include your framework, then you shouldn't do it that way; they should reference a framework embedded in your application. You can reference the framework bundle via
@executable_path
so it's relative to your application (e.g.@executable_path/../Frameworks/MyFramework.framework/
).Here's an example from Lightroom:
If they both include other third-party Objective-C frameworks, this is a bug in the plugins; the Objective-C runtime doesn't have namespaces and you can't expect any sane response when you load multiple classes with the same name. This is discussed in this question, which provides several workarounds for ObjC namespace collisions.