假使,假设
mainDict = {
"1" = {
"key1" = "ss",
"key2" = "rr",
"name" = "nm"
},
"2" = {
"key1" = "tt",
"key2" = "vv",
"name" = "gf"
},
"3" = {
"key1" = "nm",
"key2" = "vv",
"name" = "gf"
},
"4" = {
"key1" = "tt",
"key2" = "vv",
"name" = "gf"
},
}
现在您可以通过以下方式进行过滤:
NSArray *resultArray = [[mainDict allValues] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(key1 == %@) AND (key2==%@)", @"tt",@"vv"]];
试试这个来检查:
NSMutableDictionary *mainDict=[[NSMutableDictionary alloc] init];
for(int i=1; i<=3; i++)
{
[mainDict setObject:[NSDictionary dictionaryWithObjectsAndKeys:@"tt",@"key1",@"vv",@"key2",@"ttqwdwd",@"name", nil] forKey:[NSString stringWithFormat:@"%i",i]];
}
[mainDict setObject:[NSDictionary dictionaryWithObjectsAndKeys:@"tt",@"key1",@"kk",@"key2",@"ttwwdwd",@"name", nil] forKey:[NSString stringWithFormat:@"%i",4]];
[mainDict setObject:[NSDictionary dictionaryWithObjectsAndKeys:@"tt",@"key1",@"kk",@"key2",@"ttwwdwd",@"name", nil] forKey:[NSString stringWithFormat:@"%i",5]];
NSArray *resultArray = [[mainDict allValues] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(key1 == %@) AND (key2==%@)", @"tt",@"vv"]];
NSLog(@"%@",resultArray);