I have 2 NSArray
's . Like this:
NSArray *array1 = [NSArray arrayWithObjects:@"Frog", @"Cat", @"Dog", Pig];
NSArray *array2 = [NSArray arrayWithObjects:@"Pig", @"Dog", @"Cat",@"Rabbit",@"Hen", nil];
NSMutableArray *intermediate = [NSMutableArray arrayWithArray:array1];
[intermediate removeObjectsInArray:array2];
NSUInteger difference = [intermediate count];
I want to compare array1 with array2...
If array2 has any values or objects of array1 how do I tell what the index paths are for the values that are the same in array2 as the the values in array1.
In other words If Cat and Dog from array1 are found in array2. At which index path is the cat and Dog in array2...
E.g The index paths of Dog and Cat in array2 are 1 and 2 and those 2 values where matched between the 2 arrays.
Simple use Fast Enumeration for that
for(NSString* str1 in array1)
{
for(NSString* str2 in array2)
{
if([str1 isEqualToString:str2])
int index = [array2 indexOfObject:str2];
NSLog(@"The index is : %d", index);
}
}