isKindOfClass on two classes (not instances)

cocoa, inheritance, objective-c

Solution

- (BOOL)isKindOfClass:(Class)aClass

is indeed an instance method (note the -) and won't work on the class

+ (BOOL)isSubclassOfClass:(Class)aClass

is a class method (note the +) and that's what you're looking for.

But wait ! NSObject Class Reference tells us “Refer to a class only by its name when it is the receiver of a message. In all other cases [...] use the class method.”

So you will use :

[B isSubclassOfClass:[A class]] 

Problem

Class named B inherits from A (B : A) ``` [[B class] isKindOfClass:[A class]] ``` returns NO doing ``` [[B new] isKindOfClass:[A class]] ``` returns YES so the left caller must be an instance, but how to do the same with a Class ?

Original source

Related problems