Tuesday, August 30, 2011

remove duplicate values from NSMutableArray in Objective-C

NSArray *copy = [YourMutableArray copy];
 
NSInteger index = [copy count] - 1;
 
for (id object in [copy reverseObjectEnumerator]) {
 
    if ([YourMutableArray
         indexOfObject:object inRange:NSMakeRange(0, index)] 
         != NSNotFound) 
 {
        [YourMutableArray removeObjectAtIndex:index];
 
    }
 
    index--;
}
[copy release];

1 comment: