On Thu, Mar 27, 2008 at 12:01 AM, Graham Cox <[EMAIL PROTECTED]> 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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to