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

前端 未结 4 1083
半阙折子戏
半阙折子戏 2020-12-30 00:20

How to check an NSMutableArray is null or not ?

相关标签:
4条回答
  • 2020-12-30 00:44

    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) { ... }
    
    0 讨论(0)
  • 2020-12-30 00:51
    //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");
    }
    
    0 讨论(0)
  • 2020-12-30 00:59

    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
      }
      
    0 讨论(0)
  • 2020-12-30 01:04

    You can check this way also...

    if self.yourMutableArray.count == 0 {
         // Your Mutable array is empty. 
    } else {
        // Your Mutable array is not empty.
    }
    
    0 讨论(0)
提交回复
热议问题