I have 2 arrays. One is a large static group of 600 objects, the other is a small varying group of 10 objects.
I want to take any common objects between the two groups and put them in a new array.
So lets say the large group contains 600 objects named 1 to 600. The smaller group contains 9 objects: 1, 2, 3, 4, 5, 6, a, b, c. I want to be able to create a new array that contains the objects 1, 2, 3, 4, 5, 6.
What is the best way to do this?
Are you sure that you need
NSArrays? For intersections it would be better to useNSSets. For more information about the usage of NSArrays and NSSet please refer to Cocoa with Love: NSArray or NSSet, NSDictionary or NSMapTable.If you are using
NSSetyou have to create a newNSMutableSet, which has the methodintersectSet:, which can be used for your purpose:You can create a
NSMutableSetfrom anNSArrayusing theaddObjectsFromArray:method:It may be that you can also filter the
NSArrayusing thefilterUsingPredicate:method, however I have never worked withNSPredicates therefore this is only an assumption.