如何在目标C中交叉两个数组? [英] how to intersect two arrays in objective C?
本文介绍了如何在目标C中交叉两个数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个数组。 Array1包含15个对象,Array2包含4个对象。两个数组都有两个常见的对象,我只想得到那两个对象的结果数组。
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.
它应该像两个Set的交集,但是如何在Objective C中为数组做什么?请帮忙。谢谢。
It should be like intersection of two Set, but how to do in Objective C for array..? Please help. thanks.
推荐答案
使用NSMutableSet
Using NSMutableSet
NSMutableSet *set1 = [NSMutableSet setWithArray: array1];
NSSet *set2 = [NSSet setWithArray: array2];
[set1 intersectSet: set2];
NSArray *resultArray = [set1 allObjects];
这篇关于如何在目标C中交叉两个数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文