Created
September 7, 2012 08:59
-
-
Save tudormunteanu/3664488 to your computer and use it in GitHub Desktop.
Deduplicate NSArray
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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