how to intersect two arrays in objective C?

爷,独闯天下 提交于 2019-11-30 14:38:37

问题


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.


回答1:


Using NSMutableSet

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


来源:https://stackoverflow.com/questions/12173903/how-to-intersect-two-arrays-in-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!