I will give you an example of how you can create and load a bundle as plugin. Hope that this will help you a lot. I must say that I agree with the other 2 (so far) answers. So...
Create an Xcode project as "Bundle" (in Xcode 3.2.6 is in New Project->Framework & Library-> select "Bundle"). Create the following files...
PClass.h
#import <Foundation/Foundation.h>
@interface PClass : NSObject {
}
- (NSString*) stringMessage;
@end
PClass.m
- (NSString*) stringMessage {
return @"Hallo from plugin";
}
in the projects .plist file add the following two entries:
"Bundle display name" "MyPlugin"
"Principal class" "PClass"
Then compile the project and move the binary (.../build/Debug/yourPlugin.bundle) to a folder you like to keep your plugins of a project of yours (may be copied into aProject.app/Plugins/ with a little extra care).
Then to an already Xcode project add the following:
- (void) loadPlugin {
id bundle = [NSBundle bundleWithPath:@"the path you/placed/yourPlugin.bundle"];
NSLog(@"%@", [[bundle infoDictionary] valueForKey:@"CFBundleDisplayName"]);
// Here you can preview your plugins names without loading them if you don't need to or just to
// display it to GUI, etc
NSError *err;
if(![bundle loadAndReturnError:&err]) {
// err
} else {
// bundle loaded
Class PluginClass = [bundle principalClass]; // here is where you need your principal class!
// OR...
//Class someClass = [bundle classNamed:@"KillerAppController"];
id instance = [[PluginClass alloc] init];
NSLog(@"%@", [instance stringMessage]);
[instance release]; // If required
[bundle unload]; // If required
}
}
You have just loaded a bundle via its Principal Class as a plugin of an application.