在 JSON
解析期间(使用 AFNetwork json getter 完成),我有以下代码片段:
if (![[data class] isKindOfClass:[NSDictionary class]]) {
DLog(@"%@ was not kind of class NSDictionary",[data class]);
return;
}
但由于某些原因,If
语句变为true,函数返回:
> __NSCFDictionary was not kind of class NSDictionary
但是 __NSCFDictionary
不应该是特定的类 NSDictionary
吗?或者如果这是错误的验证方式,我该怎么做?
更新:
我尝试扭转它,就像这样:
if (![[NSDictionary class] isKindOfClass:[data class]]) {
DLog(@"%@ was not kind of class NSDictionary",[data class]);
return;
}
仍然不起作用:
__NSCFDictionary was not kind of class NSDictionary
最佳答案
根据docs
isKindOfClass:
Returns a Boolean value that indicates whether the receiver is an instance of given class or an instance of any class that inherits from that class. (required)
您正在使用
[data class]
它将返回一个字符串..您必须仅使用对象/实例,即
if (![data isKindOfClass:[NSDictionary class]])
关于iphone - 为什么 __NSCFDictionary 不是一种 NSDictionary 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14500229/