• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Plugin Interface
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Plugin Interface


  • Subject: Re: Plugin Interface
  • From: Carlos Weber <email@hidden>
  • Date: Mon, 25 Jun 2001 09:01:43 -1000

On Monday, June 25, 2001, at 07:38 , David Remahl wrote:

Yes, I want something like the way screen saver plugins work, but I do not know how to link to them, being the host application...Does anyone know of any examples of this? Anyway, I'll check out the archives. Thanks for you time and inbox space.

Ryan's example code looks great, and should get you going. As an alternative to using NSFileManager routines to locate your plugins you can use NSBundle routines, such as -pathsForResourcesOfType:inDirectory: and friends. Here's a routine I wrote (last night!) that creates an array of plugins for my program to use later:

- (NSArray *)_getProblemPlugins
{
NSArray *pathsArray = [[NSBundle mainBundle]
pathsForResourcesOfType: FCProblemPluginExtension
inDirectory: FCProblemPluginDirectory];
if ( [pathsArray count] == 0 ) {
return nil;
} else {
NSMutableArray *pluginArray = [NSMutableArray arrayWithCapacity: 8];
NSBundle *pluginBundle;
Class pluginClass;
id newPlugin;
int i, pluginCount = [pathsArray count];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
for (i = 0; i < pluginCount; i++) {
pluginBundle = [[NSBundle alloc]initWithPath: [pathsArray objectAtIndex: i]];
if (pluginClass = [pluginBundle principalClass]) { // get the bundle's class
newPlugin = [[pluginClass alloc]init]; // instantiate it
if ([newPlugin conformsToProtocol: @protocol(FCProblemPlugin)]) { // check it
// add it to the array
[pluginArray addObject: newPlugin];
}
[newPlugin release];
}
[pluginBundle release];
pluginBundle = nil;
pluginClass = nil;
}
[pool release];
return pluginArray;
}
}

The documentation for NSBundle has some tantalizing holes (e.g., the description of the routine -builtinPluginsPath is, you guessed it, forthcoming), but you should read it carefully. I lost about an hour yesterday from not having noted that the plugin project has to compile the .m file containing the plugin's principal class first, before any other files!


  • Follow-Ups:
    • Re: Plugin Interface
      • From: David Remahl <email@hidden>
  • Prev by Date: <no subject>
  • Next by Date: Found the problem...
  • Previous by thread: Re: Plugin Interface
  • Next by thread: Re: Plugin Interface
  • Index(es):
    • Date
    • Thread