//利用字典对键唯一的情况
-(NSMutableArray *)GetOutRepeat1From:(NSArray *)arr{
NSMutableDictionary *dic = [[NSMutableDictionary alloc]initWithCapacity:0];
for(id key in arr)
{
[dic setValue:key forKey:[NSString stringWithFormat:@"%@",key]];
}
return [NSMutableArray arrayWithArray:[dic allKeys]];
}
//转化set对象
-(NSMutableArray *)GetOutRepeat2From:(NSArray *)arr{
NSSet *set = [NSSet setWithArray:arr];
return [NSMutableArray arrayWithArray:[set allObjects]];
}
//利用数组包含对象的函数处理
-(NSMutableArray *)GetOutRepeat3From:(NSArray *)arr{
NSMutableArray *needArr = [[NSMutableArray alloc]init];
for (id key in arr) {
if (![needArr containsObject:key]) {
[needArr addObject:key];
}
}
return needArr;
}
//苹果自己的函数处理
-(NSMutableArray *)GetOutRepeat4From:(NSArray *)arr{
arr = [arr valueForKeyPath:@"@distinctUnionOfObjects.self"];
return [NSMutableArray arrayWithArray:arr];
}
转载 http://www.tuicool.com/articles/jm6jiuq