ios - 如何查找 NSMutableDictionary 中的重复项?

标签 ios nsarray nsdictionary nsmutabledictionary

伪代码:

NSArray *arr1 = {"mike","george","Tim","Tom"...}
NSArray *arr2 = {"mike","george","Chris","Adam"...}
NSArray *arr3 = {"Don","george","mike","Tom"...}
NSArray *arr4 = {"george","Nicole","Moe","mike"...}

//Add these arrays to the dictionary
for(int i=0; i<n, i++)
   [dictionary addObject:arr[i]];

我想找到所有数组中存在的重复值,而不是某些数组中。 在此示例中,该值将为 {"george","mike"}。

最佳答案

NSArray *arr1 = @[@"mike",@"george",@"Tim",@"Tom" ];
NSArray *arr2 = @[@"mike",@"george",@"Chris",@"Adam" ];
NSArray *arr3 = @[@"Don",@"george",@"mike",@"Tom" ];
NSArray *arr4 = @[@"george",@"Nicole",@"Moe",@"mike" ];

NSMutableSet *intersection = [NSMutableSet setWithArray:arr1];
[intersection intersectSet:[NSSet setWithArray:arr2]];
[intersection intersectSet:[NSSet setWithArray:arr3]];
[intersection intersectSet:[NSSet setWithArray:arr4]];

NSArray *duplicates = [intersection allObjects];

NSLog(@"duplicates=%@", duplicates);

duplicates 包含一个数组,其中包含全部出现的值:

duplicates=(
  mike,
  george
)

关于ios - 如何查找 NSMutableDictionary 中的重复项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13503990/

相关文章:

ios - 警告 : "Sending ' NSObject *' to parameter of incompatible type ' id<NSCopying>'

ios - 在 iOS (Swift) 上使用当前选择的相机

ios - iPad SplitViewController - 使用 iPhone Storyboard ViewController

iOS:在单元测试中创建加密 key 时出错

iphone - 在 iPhone 应用内完成应用内购买后删除广告横幅

objective-c - 使用 NSDictionary 将索引存储为值来加快 NSArray 查找

ios - 如何访问对象的恢复 ID(为什么为空?)

swift 4.0 : How do i move all the NSArray values to NSDictionary dynamically?

iOS 将方法名称添加到 NSDictionary 并随后调用

iphone - 将 NSArray 插入 NSDictionary