Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to intersect two arrays in objective C?

Tags:

I have two arrays . Array1 contains 15 objects and Array2 contains 4 objects. There are 2 common objects from both array, I just want to get that resulted array of that 2 objects.

It should be like intersection of two Set, but how to do in Objective C for array..? Please help. thanks.

like image 722
Dishant Avatar asked Aug 29 '12 08:08

Dishant


1 Answers

Using NSMutableSet

NSMutableSet *set1 = [NSMutableSet setWithArray: array1]; NSSet *set2 = [NSSet setWithArray: array2]; [set1 intersectSet: set2]; NSArray *resultArray = [set1 allObjects]; 
like image 130
jcesarmobile Avatar answered Mar 03 '23 12:03

jcesarmobile