How to check if array is null or empty?

前端 未结 12 1430
后悔当初
后悔当初 2021-01-31 07:32

I want to check if my array is empty or null, and on base of which I want to create a condition for example.

if(array ==  EMPTY){
//do something
}
12条回答
  •  庸人自扰
    2021-01-31 07:58

    null and empty are not the same things , i suggest you treat them in differently

    if (array == [NSNull null]) {
        NSLog(@"It's null");
    } else if (array == nil || [array count] == 0) {
         NSLog(@"It's empty");
    }
    

提交回复
热议问题