检查NSDrray的两个NSArray之间的常见值

时间:2012-06-05 12:03:46

标签: objective-c ios5

我有两个NSArray,notiCloud和notiLoc,两者都具有相同结构的NSDictonary。我需要知道如何检查NSArray中有多少NSDictionary,例如使用密钥@“id”。

非常感谢。

1 个答案:

答案 0 :(得分:3)

// Create arrays of the IDs only
NSArray *notiCloudIDs = [notiCloud valueForKey:@"id"];
NSArray *notiLocIDs = [notiLoc valueForKey:@"id"];

// Turn the arrays into sets and intersect the two sets
NSMutableSet *notiCloudIDsSet = [NSMutableSet setWithArray:notiCloudIDs];
NSMutableSet *notiLocIDsSet = [NSMutableSet setWithArray:notiLocIDs];
[notiCloudIDsSet intersectSet:notiLocIDsSet];

// The IDs that are now in notiCloudIDsSet have been present in both arrays
NSLog(@"Duplicate IDs: %@", notiCloudIDsSet);