• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting a list of all classes, etc...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Getting a list of all classes, etc... (From: Graham Cox <email@hidden>)
 >Re: Getting a list of all classes, etc... (From: "Sherm Pendley" <email@hidden>)
 >Re: Getting a list of all classes, etc... (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: Core Data & Sheet problem
  • Next by Date: Re: Core Data & Sheet problem
  • Previous by thread: Re: Getting a list of all classes, etc...
  • Next by thread: CoreAnimation weird problems with NSView animator
  • Index(es):
    • Date
    • Thread