Re: plugin theory
Re: plugin theory
- Subject: Re: plugin theory
- From: Ed Baskerville <email@hidden>
- Date: Sun, 9 Apr 2006 11:40:38 -0700
Hi Ryan,
Let me see if I have this right: your confusion is between loading
the bundle and instantiating the class. Your intuition is right;
there's a difference. When you load the bundle, either explicitly
using the load method or implicitly using, e.g., the principalClass
method, the bundle--along with the data structures representing the
contained classes--get loaded into the running application. This does
not create an instance of the class. That doesn't happen until you
actually call alloc/init on the principal class (or, if you're
feeling complicated, some other class) in the bundle.
In many applications, plug-ins will just get instantiated once, say,
to add a particular feature to the application's controller code. In
your case, you want to create multiple instances, and this is just
fine if it makes sense for your design.
To see it in code (typed directly into Mail, may have typos, blah
blah blah...):
NSString *path; // Assume this exists
// Just creates an NSBundle object; no code is loaded.
NSBundle *bundle = [NSBundle bundleWithPath:path];
// Since the code has not yet been loaded, this implicitly loads the
code and then returns the principal class.
Class principalClass = [bundle principalClass];
// Later in your code, create an instance of this class and add it to
an array of instances
NSMutableArray *instancesOfSomePlugin; // Assume this exists
// ...
id instance = [[principalClass alloc] init];
[instancesOfSomePlugin addObject:[instance autorelease]];
Andreas said you can just scan the directory. This would work most of
the time, but you might want to validate the plugin to make sure it
actually contains code, conforms to the right protocol, etc., so I'd
advise actually loading the plugins upfront, unless you're expecting
there to be lots and lots of them and you don't want to slow down the
app launch time.
There's information about all of this at Apple's site as well
(perhaps you've already seen it), although it doesn't specifically
address your multiple-instances question:
http://developer.apple.com/documentation/cocoa/Conceptual/LoadingCode/
index.html
Hope that helps.
--Ed
On Apr 9, 2006, at 11:14 AM, Andreas Mayer wrote:
Am 09.04.2006 um 19:58 Uhr schrieb Ryan Glover:
Is it possible to create a list of available plugins without
creating an instance of each of the plugins?
Of course. Just scan the available folders for plug-ins and display
that information. Since you are responsible for loading the plug-
ins, you are of course free to not load them at all.
I'm not really sure I understand what your actual problem is.
Cocoa Dev Central has a tutorial about using plug-ins. I suggest
you use this as a starting point and ask again if any specific
problem crops up:
http://cocoadevcentral.com/articles/000068.php
Andreas
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40edbaskerville.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden