Does a comparable function to 'isKindOfClass:' exist for comparing a 'Class' to another (i.e. without constructing an instance of either class). For example, given:
Class class = NSClassFromString(@"NSNumber");
[NSNumber isKindOfClass:class]; // YES
[NSString isKindOfClass:class]; // NO
Thanks!
+ (BOOL)isSubclassOfClass:(Class)aClass
and
Class theClass = NSClassFromString(@"NSNumber");
if ([NSNumber class] == theClass) {
// YES
}
There is never more than 1 instance of a class, that's why ==
is the operator you're looking for.
Yeah, you can do:
[NSNumber isSubclassOfClass:class]; //YES
[NSString isSubclassOfClass:class]; //NO
These are class methods on NSObject
.
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