Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

isKindOfClass on two classes (not instances)

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 ?

like image 524
Peter Lapisu Avatar asked Dec 01 '22 03:12

Peter Lapisu


1 Answers

- (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]] 
like image 177
Nicolas Avatar answered Dec 04 '22 12:12

Nicolas