Objective-C:加载“库”使用反射
我的任务是使用 XCode for OSX 创建一个应用程序。该应用程序需要能够加载并运行动态确定的单独“模块”(即,一个用户可能购买了模块 1 和 2,而用户 2 可能购买了模块 3 和 6——只有购买的模块才应该“跑步”)。
在 C# 中,我将创建一个“库”项目(仅编译为 DLL)。当用户购买模块时,我将提供适当的 DLL 文件,然后我的应用程序将使用反射查找并加载/运行 DLL。
在 XCode 中与此等效的是什么?我可以创建一个“库”,然后使用反射加载它吗?请记住,应用程序无法预先了解模块,因为在某些情况下,用户甚至不拥有模块文件。我看到了各种选项,例如“Cocoa Framework”和“Cocoa Library”以及“C/C++ Library”。每个人都做什么?是否可以做我需要的事情?
I'm tasked with creating an application using XCode for OSX. This application needs to be able to load and run separate "modules" which will be determined dynamically (i.e., one user may have purchased modules 1 & 2, while user 2 would have purchased modules 3 and 6 -- only purchased modules should "run").
In C#, I would create a "library" project (that compiles to just a DLL). When the user purchases a module, I'd supply the appropriate DLL files and then my app would look for and load/run the DLL using reflection.
What would be the equivalent to this in XCode? Can I create a "library" and then load it using reflection? Keeping in mind that the app can't have prior knowledge of the module since in some cases, the user wouldn't even own the module files. I see various options such as "Cocoa Framework" and "Cocoa Library" as well as "C/C++ Library." What does each do and would any work to do what I need?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建一个捆绑包。 Xcode 有这方面的模板(称为“Loadable Bundle”,图标是乐高积木)。您通常使用
NSBundle
的load
方法加载包。加载它的一个例子是:
您最终可以提供一个插件可以使用的框架,其中可以包括协议和类。例如,您可以检查包的主要类是否是框架中特定类的子类,这样您就不会发送插件不响应的任何消息。
You can create a bundle. Xcode has templates for this (it is called "Loadable Bundle" and the icon is a Lego brick). You typically load a bundle using
NSBundle
'sload
method.An example of loading it would be:
You can eventually provide a framework that the plugins can use, which can include protocols and classes. You may, for example check if the principle class of the bundle is a subclass of a specific class in your framework, so you don't send any messages the plugin doesn't respond to.