我有两个NSArray,notiCloud和notiLoc,两者都具有相同结构的NSDictonary。我需要知道如何检查NSArray中有多少NSDictionary,例如使用密钥@“id”。
非常感谢。
答案 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);