Schizophrenic plugins

Lately I was driving home and I was thinking a bit about BSInspectors. The inspectors use plugins, but the plugins always come in pairs, which is first: annoying to create, and second: annoying to maintain. I’d really prefer to go for a one plugin per plugin architecture ;-).

I ended up with a concept that I’ll call Schizophrenic plugins in the post. Basically they are plugins that contain two or more principal classes. The benefits are obvious: you only need to create one bundle/plugin and you only need to install and load one bundle.

Why would you need it in first place? BSInspectors is a plugin for Xcode that has plugins itself, and these plugins are divided into two parts, the Xcode part and the application part. The application part is loaded into the application to provide the data for objects in a proper way. The Xcode part can then use this data to display the objects in a much more convenient way.

So how can such a plugin be implemented? The implementation is as simple as the idea. You just ask the plugin’s principal class for the class you want. The principal class for BSInspector plugins for example could look like this:

@interface MyBSInspectorPlugin {
}

+ (Class)inspectorClass;
+ (Class)debugObjectClass;

Simple interface, isn’t it? Your plugin loader then just has to do something like:

	...
	Class aClass = [[bundle principalClass] inspectorClass];
	id myInstance = [[aClass alloc] init];
	... //whatever

instead of:

	...
	Class aClass = [bundle principalClass];
	id myInstance = [[aClass alloc] init];
	... //whatever

I think I’ll implement it into BSInspectors some day, but till then I’ll first do a hell of a lot more work for CuteClips3 😉

Karsten

2 Responses to “Schizophrenic plugins”

  1. Jordy/Jediknil Says:

    It took me a while to realize this, but all [NSBundle principleClass] does is look up the NSPrincipleClass key and use NSStringFromClass. (At least conceptually.) Which means you can just use your own key in Info.plist with the name of the inspector class (or whatever) and avoid having to +initialize the actual “principle object” class. Of course, this only helps if you weren’t already planning to use the principle class.

  2. Jordy/Jediknil Says:

    Sorry, that should have been -[NSBundle classNamed:], not NSStringFromClass().