主应用程序和可加载包之间的通信

时间:2013-03-04 08:43:36

标签: objective-c macos cocoa nsbundle

好的,这是相当不言自明的。

假设我们已经获得了可可应用程序。 让我们假设你已经有了一些“插件”,打包成独立的可加载包。

这是当前正在加载bundle的方式(假设插件的“主类”实际上是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"];
}

现在,抓住这个问题:

  • 如何将一些主要应用程序的对象“发布”到插件中?
  • 如何让我的插件“知道”我的主要应用程序的类?
  • 甚至可以在它们之间实际建立某种通信,例如,该插件可以与我的主应用程序进行交互?如果是这样,怎么样?

SIDENOTES:

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

0 个答案:

没有答案
相关问题