Reputation: 147
I have two NSArray
s, array1
and array2
.
If array1
has values of 7
,8
,9
,10
and array2
has values of 7
,9
,10
; how would I remove only the variables that do not exist within array2
.
So array1
would go from 7
,8
,9
,10
- to 7
,9
,10
.
Upvotes: 0
Views: 125
Reputation: 6692
Use the NSMutableSet intersectSet:
method to find the intersection of both arrays.
E.g. something like:
NSMutableSet *intersection = [NSMutableSet setWithArray:firstArray];
[intersection intersectSet:[NSSet setWithArray:secondArray]];
NSArray *intersectionArray = [intersection allObjects];
Upvotes: 1