Re: Getting a list of all classes, etc...
Re: Getting a list of all classes, etc...
- Subject: Re: Getting a list of all classes, etc...
- From: Graham Cox <email@hidden>
- Date: Thu, 27 Mar 2008 15:01:57 +1100
What's the correct file to include to obtain these functions? I
thought it would come along with <Foundation/Foundation.h>, but I'm
getting the following:
: error: implicit declaration of function 'objc_getClassList'
Also, I'm trying to heed the warning in the docs that state:
"You cannot assume that class objects you get from this function are
classes that inherit from NSObject, so you cannot safely call any
methods on such classes without detecting that the method is
implemented first."
So I need a way to test the resulting Classes to see if they really do
derive from NSObject. What's a good (safe) way to do that? I'm trying
to compare the result of class_getSuperclass with [NSObject class],
but I'm not sure this is right.
------
S.O.S.
On 27 Mar 2008, at 1:19 pm, Sherm Pendley wrote:
On Wed, Mar 26, 2008 at 10:01 PM, Graham Cox
<email@hidden> wrote:
Is there a way to obtain from the runtime a list of all classes that
are subclasses of a given class, or failing that, a list of all
classes that I can iterate and test with isKindOfClass:?
Here's the function I use in CamelBones to iterate through all
registered classes. It hasn't been updated to Leopard's new ObjC 2.0
runtime yet, but neither have most Mac users. :-)
// Create Perl wrappers for all registered ObjC classes
void REAL_CBWrapRegisteredClasses(void) {
int numClasses;
Class *classes;
int i;
classes = NULL;
numClasses = objc_getClassList(NULL, 0);
if (numClasses > 0) {
classes = malloc(sizeof(Class) * numClasses);
objc_getClassList(classes, numClasses);
for(i=0; i < numClasses; i++) {
REAL_CBWrapObjectiveCClass(classes[i]);
}
free(classes);
}
}
sherm--
_______________________________________________
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