Finding all subclasses of a class ?
Finding all subclasses of a class ?
- Subject: Finding all subclasses of a class ?
- From: Eric Morand <email@hidden>
- Date: Thu, 25 Aug 2005 15:59:40 +0200
Is there a way to find all subclasses of a class ?
At runtime, I want to be able to find all subclasses of my custim
Class : EutopiaModule.
Here is what I'm doing :
int numClasses;
Class * classes = NULL;
classes = NULL;
numClasses = objc_getClassList(NULL, 0);
if( numClasses > 0 )
{
classes = malloc( sizeof(Class) * numClasses );
(void) objc_getClassList( classes, numClasses );
}
int i;
for (i = 0; i < numClasses; i++ )
{
if ( [classes[i] respondsToSelector:@selector
(isSubclassOfClass:)] )
{
if ( [classes[i] isSubclassOfClass:[EutopiaModule class]] )
{
NSLog (NSStringFromClass(classes[i]));
}
}
}
It doesn't work. The app crash with the following messages :
2005-08-25 15:57:10.104 €utopia[11296] *** +[Object
respondsToSelector:]: warning: Object compatibility method has been
executed at least once. Convert source code off it NOW!
2005-08-25 15:57:10.108 €utopia[11296] AccountsTransactionsModule
2005-08-25 15:57:10.116 €utopia[11296] *** Selector
'respondsToSelector:' sent to dealloced instance 0xa2881c9c of class
UNKNOWN.
Break at '-[_NSZombie respondsToSelector:]' to debug.
2005-08-25 15:57:10.116 €utopia[11296] An uncaught exception was
raised
2005-08-25 15:57:10.116 €utopia[11296] *** Selector
'respondsToSelector:' sent to dealloced instance 0xa2881c9c of class
UNKNOWN.
Break at '-[_NSZombie respondsToSelector:]' to debug.
2005-08-25 15:57:10.116 €utopia[11296] *** Uncaught exception:
<NSGenericException> *** Selector 'respondsToSelector:' sent to
dealloced instance 0xa2881c9c of class UNKNOWN.
Break at '-[_NSZombie respondsToSelector:]' to debug.
What is the right way to do this ?
Eric.
_______________________________________________
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