如果你有一个 NSMutableArray 和三个 NSDictionarys 像这样:
{
name:steve, age:40;
name:steve, age:23;
name:paul, age:19
}
我如何将它变成一个只有两个字符串的数组 { steve, paul }。换句话说,来自原始 NSMutableArray 的唯一名称?有没有办法使用块来做到这一点?
最佳答案
类似的东西:
NSMutableSet* names = [[NSMutableSet alloc] init];
[array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop)) {
[names addObject:[obj valueForKey:@"name"]];
}];
[names allObjects] 将返回一个唯一名称的 NSArray
关于ios - 带有 NSDictionary 项的 NSMutableArray 中的唯一项?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3978556/