NSArray - check if objects are in an array?

后端 未结 3 1460
北荒
北荒 2020-12-21 16:20

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 grou

3条回答
  •  一整个雨季
    2020-12-21 16:52

    The easiest (but not necessarily fastest (?)) way would be something like

    NSMutableSet *intersection = [NSMutableSet setWithArray:smallArray];
    [intersection intersectSet:[NSSet setWithArray:bigArray];
    NSArray *result = [NSArray arrayWithSet:intersection];
    

    You'll have to sort the resulting array again, however.

提交回复
热议问题