本文介绍了ios检查nsarray == null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到了来自 JSON
的回复,并且工作正常,但我需要检查一些 null
值,
I'm receiving some response from JSON
, and is working fine, but I need to check for some null
values,
我找到了不同的答案,但似乎仍然没有工作,
I have found different answers but seems is not working still,
NSArray *productIdList = [packItemDictionary objectForKey:@"ProductIdList"];
我试过
if ( !productIdList.count ) //which breaks the app,
if ( productIdList == [NSNull null] ) // warning: comparison of distinct pointer types (NSArray and NSNull)
那么发生了什么?如何解决这个问题并在我的数组中检查 null
?
So what is happening? How to fix this and check for null
in my array?
谢谢!
推荐答案
使用演员阵容消除警告:
Eliminate the warning using a cast:
if (productIdList == (id)[NSNull null])
如果 productIdList
实际上是 [NSNull null]
,然后执行 productIdList.count
会引发异常,因为 NSNull
无法理解计数
消息。
If productIdList
is in fact [NSNull null]
, then doing productIdList.count
will raise an exception because NSNull
does not understand the count
message.
这篇关于ios检查nsarray == null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!