Re: Getting classes from bundles in an array
Re: Getting classes from bundles in an array
- Subject: Re: Getting classes from bundles in an array
- From: Ondra Cada <email@hidden>
- Date: Thu, 15 Aug 2002 14:51:51 +0200
On Thursday, August 15, 2002, at 10:36 , David Newberry wrote:
NSArray *getPluginBundles( void )
{
NSEnumerator *e;
NSString *dir;
BOOL isDir;
NSString *scanDir;
NSMutableArray *ret;
ret = [[NSMutableArray alloc] initWithCapacity:5];
should be autoreleased, to conform with Cocoa general API and to prevent
potential leak.
scanDir = [[[NSBundle mainBundle] bundlePath]
stringByAppendingPathComponent:@"../plugins"];
if (![[NSFileManager defaultManager] fileExistsAtPath:scanDir
isDirectory:&isDir]) return nil;
if (!isDir) return nil;
e = [[[NSFileManager defaultManager] directoryContentsAtPath:scanDir]
objectEnumerator];
while (dir = [e nextObject]) {
if ([[dir pathExtension] isEqualToString:@"bundle"])
[ret addObject:[[NSBundle bundleWithPath:[NSString
stringWithFormat:@"%@/%@", scanDir, dir]] retain]];
No need to retain here (an array retains its contents itself).
}
return ret;
}
The only thing I'm doing with the array is this within a loop:
plugin = [plugins objectAtIndex:index];
pluginClass = [plugin classNamed:@"BEPlugin"];
I know that the correct bundles are being added to the array. If I log a
description of the bundle before trying to access the class, I can see
that it is indeed the correct file, and it shows the bundle as being
loaded. The pluginClass variable stays fixed with the value 0x0 though...
(for the first but not the second bundle...) I'm at a loss.
Looks like in the first bundle the class is not there at all... you
completely sure there is? If you switch the order bundles are stored into
the array (by eg. renaming them, or by using insertObject:atIndex:0
instead of addObject:), do still the first pluginClass==Nil and the second
one !=Nil?
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.