0
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 过滤键的值

4

1 回答 1

1

这将打印所有字典的键“名称”的值

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);
于 2012-12-25T13:40:21.797 回答