Assume that
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"
},
}
Now you can filter by the following way:
NSArray *resultArray = [[mainDict allValues] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(key1 == %@) AND (key2==%@)", @"tt",@"vv"]];
try this to check:
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);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…