如何编写谓词来过滤字典数组?

时间:2014-12-29 11:22:47

标签: ios objective-c arrays dictionary

我有字典数组,字典包含键作为NSString,值作为整数。我尝试了以下代码但没有得到结果。

NSPredicate *objPredicate = [NSPredicate predicateWithFormat:@"%@ = %@", key, [NSNumber numberWithInt:value]];

NSArray  *filteredArray = [array filteredArrayUsingPredicate:objPredicate];

1 个答案:

答案 0 :(得分:1)

使用此:

NSPredicate *objPredicate = [NSPredicate predicateWithFormat:@"self[%@] = %@", key, @(value)];

NSArray  *filteredArray = [array filteredArrayUsingPredicate:objPredicate];