objective-c 如何检查 NSMutableArray 的实例是否为空
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2048048/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 22:44:50 来源:igfitidea点击:
How to check if an instance of NSMutableArray is null or not
提问by S.P.
How to check an NSMutableArrayis null or not ?
如何检查一个NSMutableArray是否为空?
回答by Alex Reynolds
If you want to check if it is empty:
如果要检查它是否为空:
if ([myMutableArray count] == 0) { ... }
If you want to check if the variable is nil:
如果要检查变量是否为nil:
if (!myMutableArray) { ... }
or:
或者:
if (myMutableArray == nil) { ... }
回答by S.P.
//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");
}
回答by saurabh rathod
There are multiple ways to check it.
有多种方法可以检查它。
if (array == [NSNull null]) { //myarray is blank }if(array.count==0) { //myarray is blank }if(array == nil) { //my array is blank }
if (array == [NSNull null]) { //myarray is blank }if(array.count==0) { //myarray is blank }if(array == nil) { //my array is blank }
回答by D.M
You can check this way also...
您也可以通过这种方式检查...
if self.yourMutableArray.count == 0 {
// Your Mutable array is empty.
} else {
// Your Mutable array is not empty.
}

