In a document based Cocoa app, I am instantiating several objects (plugins) from external bundles using:
- (NSMutableArray *)getPluginsOfType:(Class)type;
{
NSBundle *main = [NSBundle mainBundle];
NSArray *allPlugins = [main pathsForResourcesOfType:@"bundle" inDirectory:@"../PlugIns"];
NSMutableArray *availablePlugins = [NSMutableArray array];
for (NSString *path in allPlugins)
{
NSBundle *pluginBundle = [NSBundle bundleWithPath:path];
[pluginBundle load];
Class principalClass = [pluginBundle principalClass];
[availablePlugins addObject:principalClass];
}
return availablePlugins;
}
Within each of those, a nib file is loaded upon init, which binds the root view with a property in my plugin class. Below a minimal Plugin class definition:
@interface Plugin
@property (strong) IBOutlet NSView *thePluginView;
@end
@implementation Plugin
- (instancetype)init
{
self = [super init];
if (self)
{
[NSBundle loadNibNamed:@"NibName" owner:self];
}
return self;
}
@end
While this works fine, I want to replace the above call to NSBundle (because it's deprecated for OS X 10.8+), and replace it with:
[[NSBundle mainBundle] loadNibNamed:@"NibName" owner:self topLevelObjects:nil];
However, using mainBundle in this case naturally fails to set the top level object reference in my Plugin class, I suspect cause mainBundle has nothing to do with the Plugin's bundle.
How would I go about achieving that? Is there a way to find the "current" bundle perhaps (the bundle that the Plugin class came from, so to say)?
Thanks.