OK, it's rather self-explanatory.
Let's say we've got our cocoa application. Let's all assume that you've already got some "plugins", packaged as independent loadable bundles.
This is how bundles are currently being loaded (given that the plugin's "principal class" is actually an NSWindowController
subclass :
// 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"];
}
Now, here's the catch :
- How do I "publish" some of my main app's objects to the plugin?
- How do I make my plugin "know" about my main app's classes?
- Is it even possible to actually establish some sort of communication between them, so that e.g. the plugin can interact with my main app? And if so, how?
SIDENOTES :
- Could using Protocols eliminate the "unknown selector" errors and the need for extensive use of
performSelector:withObject:
? - Obviously I can set and get value to-and-from my newly created
mainWindowController
as long as they're defined as properties. But is this the most Cocoa-friendly way?