Reputation: 4921
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?
Upvotes: 28
Views: 17265
Reputation: 25692
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.
Upvotes: 62