Re: List classes in Bundle?
Re: List classes in Bundle?
- Subject: Re: List classes in Bundle?
- From: Robert Mullen <email@hidden>
- Date: Thu, 23 Jul 2009 10:59:29 -0700
This is the method that works well for me. There is a bit of overhead
since you are looking at all classes but it still seems to be pretty
quick. Here is the quick and dirty routine as it works for me with
bits cabbaged from different sources. This IS NOT meant to be a
demonstration of production coding style but does work for my
prototyping application. Feel free to correct my blatant errors so
that anyone looking for a reasonable way to do this can find it on the
list. Also note that I am looking in the main bundle for my classes
because this is just a prototype. In the real world this would almost
certainly be different bundle. Thanks for the pointers guys.
-(void)getClasses
{
int i, numClasses = 0, newNumClasses = objc_getClassList(NULL, 0);
Class *mClass = NULL;
while (numClasses < newNumClasses) {
numClasses = newNumClasses;
mClass = realloc(mClass, sizeof(Class) * numClasses);
newNumClasses = objc_getClassList(mClass, numClasses);
}
for (i=0; i<numClasses; i++) {
@try
{
if ([NSBundle bundleForClass:mClass[i]]==[NSBundle mainBundle])
{
[classes addObject:[mClass[i] description]];
}
}
@catch (id theException) {
NSLog(@"Exception");
}
}
free(mClass);
}
On Jul 22, 2009, at 10:05 AM, glenn andreas wrote:
On Jul 22, 2009, at 12:00 PM, Robert Mullen wrote:
Is there a way to actually list all the classes in a given bundle?
I know I can look one up if I know the name but I would like to
actually be able to present a list.
If the bundle is loaded, you should be able to iterate through all
the classes in the system (using the various routines in the
runtime), and check to see if bundleForClass returns the bundle you
are looking for.
If it hasn't been loaded, you can parse the macho file format and
examine the objective-c sections, but that's a lot of work...
Glenn Andreas email@hidden
<http://www.gandreas.com/> wicked fun!
Mad, Bad, and Dangerous to Know
_______________________________________________
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