2015-11-20 125 views
0

我有两个数组,数组A有4个元素,数组B有10个元素。如何将这两个数组进行比较,以确定数组A是否包含数组B中的值。IOS如何比较两个数组的不同值和数量

这是代码。

for(int i = 0; i <= deepsightSig.count; i++){ 
    for(int p = 0; p <= feeds.count; i++){ 


     if(feeds[i] == deepsightSig[i]){ 

      badIPCount++; 


     } 
     else 
      goodIPCount++; 

    } 


} 
+0

你只需要检查arrayB包含来自Array对象 –

+0

执行数组包含的值相同类型的对象?在发送'isEqual:'消息时,等价对象是否相等? – Avi

+0

数组A和数组B包含相同类型的对象但元素数量不同。例如数组A有4个元素,但数组B有10个元素。 – zac

回答

8
NSMutableSet* set1 = [NSMutableSet setWithArray:array1]; 
NSMutableSet* set2 = [NSMutableSet setWithArray:array2]; 
[set1 intersectSet:set2]; //this will give you only the obejcts that are in both sets 

NSArray* result = [set1 allObjects]; 

如果result.count大于一则意味着数组A具有在阵列B

+0

我爱套,他们会改变你的生活 – Loxx

+1

是的Larcerax :) –