How to determine whether class B is a subclass of class A?
It is available from iOS 2.0 and later version SDK
if ([ClassB isSubclassOfClass:[ClassA class]]) { NSLog(@"yes ClassB is SubclassOfClass of ClassA");}
isSubclassOfClass:
Returns a Boolean value that indicates whether the receiving class is a subclass of, or identical to, a given class.
+ (BOOL)isSubclassOfClass:(Class)aClass
Parameters
aClass
A class object.
Return Value
YES
if the receiving class is a subclass of—or identical to—aClass
, otherwiseNO
.Availability
Available in iOS 2.0 and later.
id a= ...;if([a isKindOfClass:[A class]]){ ...}
should do the job. You rarely needs to see if it's really a sub class. See here.