Skip to content

Instantly share code, notes, and snippets.

@tudormunteanu
Created September 7, 2012 08:59
Show Gist options
  • Select an option

  • Save tudormunteanu/3664488 to your computer and use it in GitHub Desktop.

Select an option

Save tudormunteanu/3664488 to your computer and use it in GitHub Desktop.
Deduplicate NSArray
@interface NSArray (CustomFiltering)
@end
@implementation NSArray (CustomFiltering)
- (NSArray *) filterObjectsByKey:(NSString *) key {
NSMutableSet *tempValues = [[NSMutableSet alloc] init];
NSMutableArray *ret = [NSMutableArray array];
for(id obj in self) {
if(! [tempValues containsObject:[obj valueForKey:key]]) {
[tempValues addObject:[obj valueForKey:key]];
[ret addObject:obj];
}
}
[tempValues release];
return ret;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment