ios check if nsarray == null

左心房为你撑大大i 提交于 2019-11-30 09:31:41

Eliminate the warning using a cast:

if (productIdList == (id)[NSNull null])

If productIdList is in fact [NSNull null], then doing productIdList.count will raise an exception because NSNull does not understand the count message.

You can also check class of an object by using method isKindOfClass:.

For example, in your case you could do following:

if ([productIdList isKindOfClass:[NSArray class]])
{
     // value is valid
}

or (if you are sure that NSNull is indicating invalid value)

if([productIdList isKindOfClass:[NSNull class]])
{
     // value is invalid
}
Devang

You can use the isEqual selector:

if ( [productIdList isEqual:[NSNull null]] )

you should be clear what you want to check: the array is null which means the variable doesn't exist:


array == nil

Or the array has zero element which you can :


[array count] == 0
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!