我有字典数组,字典包含作为NSString的键和作为整数的值。我尝试了以下代码,但没有得到结果。
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];