how to intersect two arrays in objective C?

后端 未结 1 1810
庸人自扰
庸人自扰 2021-01-01 14:15

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 ob

1条回答
  •  有刺的猬
    2021-01-01 14:26

    Using NSMutableSet

    NSMutableSet *set1 = [NSMutableSet setWithArray: array1];
    NSSet *set2 = [NSSet setWithArray: array2];
    [set1 intersectSet: set2];
    NSArray *resultArray = [set1 allObjects];
    

    0 讨论(0)
提交回复
热议问题