0

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

非常感谢。

4

1 回答 1

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);
于 2012-06-05T12:49:38.140 回答