If you need a list of subclasses of a class, there isn't a built-in
function - you have to test them one at a time. However I had the
exact same need recently and wrote a little helper class to do it. One
thing I ran into in my situation is that I really needed to prevent
+initialize from ever getting called, because some low-level classes
in the Cocoa framework wrote certain messages to the log when they
were invoked (because they are obsolete and shouldn't be used) but
testing for the class itself was enough to trigger this.
So, my code uses a lower-level function. Here it is:
+ (NSArray*) allClassesOfKind:(Class) aClass
{
// returns a list of all Class objects that are of kind <aClass> or a
subclass of it currently registered in the runtime. This caches the
// result so that the relatively expensive run-through is only
performed the first time
BOOL classIsNSObject( const Class aClass )
{
// returns YES if <aClass> is an NSObject derivative, otherwise NO.
It does this without invoking any methods on the class being tested.
On 18 Jun 2008, at 3:19 pm, Laurent Cerveau wrote:
Hi
Is there a way to get all subclases of a class. I have a class that
I would call abstract (although I did not find any real way to
declare some methods as virtual) and would like to get a list of all
"real" subclass implementations.