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

Ios 如何编写谓词来过滤字典数组?,ios,objective-c,arrays,dictionary,Ios,Objective C,Arrays,Dictionary,我有一个字典数组,字典包含键作为字符串,值作为整数。我尝试了以下代码,但没有得到结果 NSPredicate *objPredicate = [NSPredicate predicateWithFormat:@"%@ = %@", key, [NSNumber numberWithInt:value]]; NSArray *filteredArray = [array filteredArrayUsingPredicate:objPredicate]; 使用以下命令: NSPredicat

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

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

NSArray  *filteredArray = [array filteredArrayUsingPredicate:objPredicate];
使用以下命令:

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

NSArray  *filteredArray = [array filteredArrayUsingPredicate:objPredicate];

您的字典不能有整数,只有对象可以存储在字典、数组、集合。。。您的字典中必须有一个NSNumber:这可能很好:[NSPredicate predicateWithFormat:@“%@=%@”,键,值];