Objective-C Language NSArray Comparing arrays


Example

Arrays can be compared for equality with the aptly named isEqualToArray: method, which returns YES when both arrays have the same number of elements and every pair pass an isEqual: comparison.

NSArray *germanMakes = @[@"Mercedes-Benz", @"BMW", @"Porsche",
                     @"Opel", @"Volkswagen", @"Audi"];
NSArray *sameGermanMakes = [NSArray arrayWithObjects:@"Mercedes-Benz",
                        @"BMW", @"Porsche", @"Opel",
                        @"Volkswagen", @"Audi", nil];

if ([germanMakes isEqualToArray:sameGermanMakes]) {
    NSLog(@"Oh good, literal arrays are the same as NSArrays");
}

The important thing is every pair must pass the isEqual: test. For custom objects this method should be implemented.It exists in the NSObject protocol.