如何检查NSMutableArray
是否为空?
答案 0 :(得分:77)
如果你想检查它是否为空:
if ([myMutableArray count] == 0) { ... }
如果您想检查变量是否为nil
:
if (!myMutableArray) { ... }
或:
if (myMutableArray == nil) { ... }
答案 1 :(得分:0)
//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");
}
答案 2 :(得分:0)
有多种方法可以检查它。
if (array == [NSNull null]) { //myarray is blank }
if(array.count==0) { //myarray is blank }
if(array == nil) { //my array is blank }
答案 3 :(得分:0)
你也可以这样检查......
if self.yourMutableArray.count == 0 {
// Your Mutable array is empty.
} else {
// Your Mutable array is not empty.
}