开发者

How to check if an instance of NSMutableArray is null or not

开发者 https://www.devze.com 2022-12-15 22:51 出处:网络
How to check an NSMutableArray is nu开发者_运维技巧ll or not ?If you want to check if it is empty:

How to check an NSMutableArray is nu开发者_运维技巧ll or not ?


If you want to check if it is empty:

if ([myMutableArray count] == 0) { ... }

If you want to check if the variable is nil:

if (!myMutableArray) { ... }

or:

if (myMutableArray == nil) { ... }


//if the array has a count of elements greater than 0, then the array contains elements
if(myarray.count>0){
    NSlog(@"myarray contains values/elements");
}
else{ //else the array has no elements
    NSlog(@"myarray is nil");
}


There are multiple ways to check it.

  1. if (array == [NSNull null])
    {
        //myarray is blank
    }
    
  2. if(array.count==0)
    {
        //myarray is blank
    }
    
  3. if(array == nil)
    {
        //my array is blank
    }
    


You can check this way also...

if self.yourMutableArray.count == 0 {
     // Your Mutable array is empty. 
} else {
    // Your Mutable array is not empty.
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号