• 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: Finding all subclasses of a class ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Finding all subclasses of a class ?


  • Subject: Re: Finding all subclasses of a class ?
  • From: Daniel Jalkut <email@hidden>
  • Date: Thu, 25 Aug 2005 14:33:58 -0400

Thanks for sharing this - it makes the basis for a nice command-line tool for exploring arbitrary AppKit class lineage...

Daniel

On Aug 25, 2005, at 12:25 PM, glenn andreas wrote:

Here's some code that works in an application of mine (and since it's from a working app, it doesn't suffer from "pre coffee typos"):


NSMutableSet *gAllFoos = [NSMutableSet set];
int numClasses = 0, newNumClasses = objc_getClassList(NULL, 0);
Class *classes = NULL;
while (numClasses < newNumClasses) {
numClasses = newNumClasses;
classes = (Class *)realloc(classes, sizeof(Class) * numClasses);
newNumClasses = objc_getClassList(classes, numClasses);
}
// now, can use the classes list; if NULL, there are no classes
for (int i=0;i<numClasses;i++) {
if (classes[i] == [Foo class])
continue; // don't add our abstract class
if (!CLS_GETINFO(classes[i], CLS_CLASS))
continue; // ignore meta classes as well
Class s = classes[i];
while (s) { // walk the inheritence because we don't know about this class at all
if (s == [Foo class])
break;
s = s->super_class;
}
if (s) {
// do something with it...
[gAllFoos addObject: classes[i]];
}
free(classes);
return gAllFoos;


Note that this will also find the various notifying classes (magically created by KVO), so you'll need some way to filter those out (and the way I'm doing it is based on some hierarchy specific behavior, so it's been redacted).


Glenn Andreas email@hidden <http://www.gandreas.com/> wicked fun! Widgetarium | the quickest path to widgets

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
sweater.com


This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Finding all subclasses of a class ?
      • From: glenn andreas <email@hidden>
References: 
 >Finding all subclasses of a class ? (From: Eric Morand <email@hidden>)
 >Re: Finding all subclasses of a class ? (From: glenn andreas <email@hidden>)
 >Re: Finding all subclasses of a class ? (From: Eric Morand <email@hidden>)
 >Re: Finding all subclasses of a class ? (From: glenn andreas <email@hidden>)
 >Re: Finding all subclasses of a class ? (From: Eric Morand <email@hidden>)
 >Re: Finding all subclasses of a class ? (From: glenn andreas <email@hidden>)

  • Prev by Date: Re: Compiler Warning - unknown Method
  • Next by Date: Re: Finding all subclasses of a class ?
  • Previous by thread: Re: Finding all subclasses of a class ?
  • Next by thread: Re: Finding all subclasses of a class ?
  • Index(es):
    • Date
    • Thread