开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜