Comparing of 'Class' with other 'Class' in Objective-C
Does 开发者_Go百科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
.
精彩评论