How to remove duplicates from NSMutableArray ?

By | May 21, 2011

Hi,

For removing or deleting duplicates from a NSMutableArray , use the following lines of code. It will simply check for duplicates elements and get it deleted or removed.


NSArray *tempArr= [urArray copy];

NSInteger idx = [tempArr count] - 1;

for (id object in [tempArr reverseObjectEnumerator]) {

     if ([urArray indexOfObject:object inRange:NSMakeRange(0, index)] !=NSNotFound) {

           [urArray removeObjectAtIndex:idx];
     }

idx--;

}
[tempArr release];

🙂

One thought on “How to remove duplicates from NSMutableArray ?

  1. Arvind Patel

    for (Student * data in fetchStudentDateArray)
    {
    if([datelistArray indexOfObject:data.date] == NSNotFound)
    [datelistArray addObject:data.date];
    }

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *