为什么@(NO)不是NSNumber类 [英] Why @(NO) isn't kind of class NSNumber
问题描述
我的行为很怪异,这似乎是由于iOS中的一些实习生造成的.
I have a weird behavior which seem due to some intern cooking in iOS.
当我这样做时:
id data1 = @(NO);
if ([data1 isKindOfClass:[NSNumber class]]) {
// doesn't come here.
}
但是使用 @(YES)
可以完美地工作.
But with @(YES)
it work perfectly.
首先,我想了解原因.其次,我想知道您将如何处理我的案件?(因为id也可以是文本).
First I would like to understand why. Second, I would like to know what you would do in my case ? (Since id can be also text).
答案:
实际上,@(NO)是NSNumber类,我的问题是由于其他错误.
Indeed, @(NO) is a kind a class NSNumber, and my problem was due to some other mistake.
推荐答案
对于表示 NSNumber
的实例,只需使用 @NO
和 @YES
NO
和 YES
.
Just use @NO
and @YES
for NSNumber
instances that represent NO
and YES
.
[@(NO)类]
和 [@(YES)类]
都提供 __ NSCFBoolean
.
并且 [@ NO类]
和 [@ YES类]
也会提供 __ NSCFBoolean
.
在所有四种情况下,对 isKindOfClass:[NSNumber class]
的检查均返回true.
And in all four cases a check against isKindOfClass:[NSNumber class]
returned true.
这篇关于为什么@(NO)不是NSNumber类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!