Objective c 基于单独数组中的对象的NSDictionary筛选器数组

Objective c 基于单独数组中的对象的NSDictionary筛选器数组,objective-c,nsdictionary,nspredicate,Objective C,Nsdictionary,Nspredicate,我有一个要筛选的NSDictionary数组。每个字典都包含对应于字符串对象的键“tid”。我想取出所有字典,其中键“tid”的对象不等于单独数组中包含的任何字符串对象 例如,如果我有一个名为“stringObjects”的数组和一个名为“dictionaries”的字典数组,我想在伪代码中执行以下操作: for (NSString *string in stringObjects) { //if a dictionary in dictionaries contains a string o

我有一个要筛选的NSDictionary数组。每个字典都包含对应于字符串对象的键“tid”。我想取出所有字典,其中键“tid”的对象不等于单独数组中包含的任何字符串对象

例如,如果我有一个名为“stringObjects”的数组和一个名为“dictionaries”的字典数组,我想在伪代码中执行以下操作:

for (NSString *string in stringObjects) {
 //if a dictionary in dictionaries contains a string object for it's key @"tid" which is NOT equal to *string, then put it in an array
}
我一直在尝试使用NSPredicate来实现这一点,但经过多次尝试后,我无法获得理想的结果。下面是我最近尝试的代码(实际上似乎为数组中的每个字典创建了一个数组,除了key@“tid”的对象之外):


非常感谢您的帮助。

如果我正确理解您的答案,您正在寻找NSCompoundPredicate:

NSMutableArray *predicates = [[NSMutableArray alloc] init];
for (NSString *string in stringObjects) {
    //Create an array of predicates
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"NOT (tid CONTAINS[cd] %@)",string];
    [predicates addObject:pred];
}
//Create a compound predicate from predicate array, with format P1 AND P2 AND P3 etc.
NSPredicate *compoundPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:predicates];
//Filter an your array using compoundPredicate.
NSMutableArray *predicates = [[NSMutableArray alloc] init];
for (NSString *string in stringObjects) {
    //Create an array of predicates
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"NOT (tid CONTAINS[cd] %@)",string];
    [predicates addObject:pred];
}
//Create a compound predicate from predicate array, with format P1 AND P2 AND P3 etc.
NSPredicate *compoundPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:predicates];
//Filter an your array using compoundPredicate.