Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to compare two NSMutableArray?

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

Thanks...

like image 216
Maulik Avatar asked May 26 '11 11:05

Maulik


People also ask

What is difference between NSArray and NSMutableArray?

NSArray creates static arrays, and NSMutableArray creates dynamic arrays.

What is NSMutableArray in swift?

Overview. The NSMutableArray class declares the programmatic interface to objects that manage a modifiable array of objects. This class adds insertion and deletion operations to the basic array-handling behavior inherited from NSArray .


2 Answers

return ([array1 isEqualToArray:array2]);

returns YES if arrays are equal else returns NO

like image 66
visakh7 Avatar answered Sep 29 '22 12:09

visakh7


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.

like image 42
knuku Avatar answered Sep 29 '22 13:09

knuku