NSArray *details = [NSArray arrayWithObjects:@"name",@"age",@"gender",nil];
NSArray *ray1 = @[@"ray",@"23",@"male"];
NSArray *steve1 = @[@"steve",@"23",@"male"];
NSDictionary *ray = [NSDictionary dictionaryWithObjects:ray1 forKeys:details];
NSDictionary *steve = [NSDictionary dictionaryWithObjects:steve1 forKeys:details];
NSArray *register = @[ray,steve];
我需要使用NSPredicate
仅过滤密钥的值答案 0 :(得分:1)
这将打印所有词典的键“name”的值
NSArray *details = [NSArray arrayWithObjects:@"name",@"age",@"gender",nil];
NSArray *ray1 = @[@"ray",@"23",@"male"];
NSArray *steve1 = @[@"steve",@"23",@"male"];
NSDictionary *ray = [NSDictionary dictionaryWithObjects:ray1 forKeys:details];
NSDictionary *steve = [NSDictionary dictionaryWithObjects:steve1 forKeys:details];
NSArray *reg = @[ray,steve];
NSPredicate *pr = [NSPredicate predicateWithValue:YES];
NSArray *ar = [[reg valueForKey:@"name"] filteredArrayUsingPredicate:pr];
NSLog(@"%@",ar);