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: "Sherm Pendley" <email@hidden>
- Date: Thu, 27 Mar 2008 01:01:03 -0400
On Thu, Mar 27, 2008 at 12:01 AM, Graham Cox <email@hidden> wrote:
> 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'
You might not need both of these:
#import <objc/objc-class.h>
#import <objc/objc-runtime.h>
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?
// The Class struct's super_class member is NULL for root classes,
// so climb the inheritance tree until we get to the root
while(NULL != aClass->super_class)
aClass = aClass->super_class;
// Now we have a root class, now we can check to see if it's NSObject
if (0 == strncmp(aClass->name, "NSObject", 8))
> I'm trying
> to compare the result of class_getSuperclass with [NSObject class],
> but I'm not sure this is right.
Unfortunately, -class is one of the methods you can't safely call until you
verify that you have an NSObject descendant. :-(
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