Objective c 主应用程序与可加载捆绑包之间的通信

Objective c 主应用程序与可加载捆绑包之间的通信,objective-c,macos,cocoa,nsbundle,Objective C,Macos,Cocoa,Nsbundle,好吧,这是不言自明的 假设我们已经有了cocoa应用程序。 让我们假设您已经有了一些“插件”,打包为独立的可加载捆绑包 这就是当前加载捆绑包的方式(假定插件的“主体类”实际上是NSWindowController子类: // Load the bundle NSString* bundlePath = [[NSBundle mainBundle] pathForResource:@"BundlePlugin"

好吧,这是不言自明的

假设我们已经有了cocoa应用程序。 让我们假设您已经有了一些“插件”,打包为独立的可加载捆绑包

这就是当前加载捆绑包的方式(假定插件的“主体类”实际上是
NSWindowController
子类:

// Load the bundle
NSString* bundlePath = [[NSBundle mainBundle] pathForResource:@"BundlePlugin" 
                                                       ofType:@"bundle"]
NSBundle* b = [NSBundle bundleWithPath:bundlePath];
NSError* err = nil;
[b loadAndReturnError:&err];
if (!err)
{
     // if everything goes fine, initialise the main controller
     Class mainWindowControllerClass = [b principalClass];
     id mainWindowController = [[mainWindowControllerClass alloc] initWithWindowNibName:@"PluginWindow"];
}
现在,这里有一个陷阱:

  • 如何将我的一些主应用程序对象“发布”到插件
  • 如何让我的插件“知道”我的主应用程序的类
  • 甚至有可能在它们之间建立某种通信,例如插件可以与我的主应用程序交互吗?如果有,如何实现

旁注:

  • 使用协议是否可以消除“未知选择器”错误以及广泛使用
    性能选择器:withObject:
  • 显然,我可以在新创建的
    mainWindowController
    中设置和获取值,只要它们被定义为属性。但这是最友好的方式吗

老问题。你还在寻找答案吗?