It seems that if you develop for Mac OS, NSObject
has the isSubclassOfClass
method. But when I check the iOS class reference for the same class, it does not have the method (and Xcode complains about the method).
My current solutions is to put a method -(void)iAmClassB
in there, and perform a respondsToSelector:iAmClassB
, but that seems contrived. Am I missing something?
issubclass() in Python This function returns True if the given class is the subclass of given class else it returns False. Parameters: Object: class to be checked. classinfo: class, types or a tuple of classes and types.
That is, given classes A and B, A is a subclass of B if and only if every member of A is also a member of B. If A and B are sets, then of course A is also a subset of B.
It is available from iOS 2.0 and later version SDK
if ([ClassB isSubclassOfClass:[ClassA class]]) { NSLog(@"yes ClassB is SubclassOfClass of ClassA"); }
Documentation:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With