我遇到了一段代码:
if(strcmp([obj objCType], @encode(BOOL))) == 0)
其中obj
是一种NSNumber
。
到底发生了什么?
答案 0 :(得分:5)
分手。
[obj objCType]
会返回char *
,其中包含NSValue
的Objective-C encoding。
NSNumber
是NSValue
。 @encode(BOOL)
对类型BOOL
执行相同的操作。
strcmp()
比较两个字符串。如果字符串相等,则返回0
。
strcmp(…) == 0
与相等字符串相比,则 strcmp()
返回true。
我想您会看到这种情况:如果NSValue obj
的编码等于BOOL
类型的编码,则条件返回true。