The goal is to compare two arrays as and check if they contain the same objects (as fast as possible - there are lots of objects in the arrays). The arrays cannot be checked
As per your code, you are strict to same number of elements and each object of first array should be there in second array and vice versa.
The fastest way would be to sort both the array and compare them.
Ex:
NSArray *array1=@[@"a",@"b",@"c"];
NSArray *array2=@[@"c",@"b",@"a"];
array1=[array1 sortedArrayUsingSelector:@selector(compare:)];
array2=[array2 sortedArrayUsingSelector:@selector(compare:)];
if ([array1 isEqualToArray:array2]) {
NSLog(@"both have same elements");
}
else{
NSLog(@"both having different elements");
}