how to compare two NSMutableArray?

老子叫甜甜 提交于 2019-11-29 12:39:34

问题


How can I compare two NSMutableArray ? if both are same than it should return true otherwise false.

Thanks...


回答1:


return ([array1 isEqualToArray:array2]);

returns YES if arrays are equal else returns NO




回答2:


Does isEqualToArray: method help you?

Other way is to iterate through both arrays and compare each object using isEqual: method. It is the same to calling isEqualToArray:. Note that in both variants you should implement isEqual: method in your array object class if it in not a standard class.

And right before this operations you can just compare their length, if they are not equal so there is no point of spending resources on more complicated calculations.




回答3:


Use isEqualToArray: method to compare between two array object

like this :

Method 1:

return [array1 isEqualToArray:array2]; //return YES or NO

Method 2:

if([array1 isEqualToArray:array2]) {//perform condition on YES}



回答4:


[array1 isEqualToArray:array2];



回答5:


Should be able to use the NSArray base class to compare one array with another array:

- (BOOL)isEqualToArray:(NSArray *)otherArray



回答6:


if([array1 isEqualToArray:array2]){

   }else{

   }


来源:https://stackoverflow.com/questions/6137469/how-to-compare-two-nsmutablearray

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!