Re: Correct way to tell if a path is to a .bundle?
Re: Correct way to tell if a path is to a .bundle?
- Subject: Re: Correct way to tell if a path is to a .bundle?
- From: Brad Goss <email@hidden>
- Date: Sat, 26 Sep 2009 00:55:16 -0400
Rick,
You could also use:
NSBundle pluginBundle = [NSBundle bundleWithPath: fullPath];
This will return an NSBundle object as your require or nil if fullPath
does not identify an accessible bundle directory. So...
if ( pluginBundle == nil ) ... then it is not a valid bundle.
You will also want to create a protocol that the plugin's Principal
class must conform to. So, a little snippet here for you that will
load a valid bundle that conforms to MyPluginProtocol.
- (id)loadBundleNamed:(NSString*)bundleName {
Class exampleClass;
id newInstance;
NSString *bundlePath = [NSString stringWithFormat:@"%@/
%@.mypluginext",[self pluginDirectory],bundleName];
NSBundle *bundleToLoad = [NSBundle bundleWithPath:bundlePath];
if (exampleClass = [bundleToLoad principalClass]) {
if ( [[bundleToLoad principalClass] conformsToProtocol:@protocol
(MyPluginProtocol)] ) {
newInstance = [[exampleClass alloc] initWithPlugInController:
[PluginController sharedManager] bundle:[NSBundle mainBundle]];
// initWithPluginController is a method defined by
MyPluginProtocol... so I am safe to use it
return [newInstance autorelease];
}
}
return nil;
}
Brad Goss
email@hidden
On 2009-09-24, at 21:41 , Rick Mann wrote:
I'm scanning a directory for plugins for my app. Given a path,
what's the right way to tell if it's a path to a bundle?
TIA
--
Rick
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden