XcodeMania
XcodeMania

Reputation: 305

find duplicate values in a NSMutableArray

how to know how many times a duplicate appears in my array ?

for (NSUInteger index = 0; index < count; index++)

{ 

     NSDictionary *dico = [myArray objectAtIndex:index ];

    NSString *exp = [dico objectForKey:@"name"];

               NSLog(@"index %d : %@",index,exp);
    }

this is my NSLog:

index 0 : Mike
index 1 : Peter
index 2 : Franck
index 3 : Peter

want to know where is my duplicates values.

thx

Upvotes: 0

Views: 1379

Answers (1)

Ankit Srivastava
Ankit Srivastava

Reputation: 12405

If I am not wrong NSSet was designed to do this... try this..

NSSet *uniqueElements = [NSSet setWithArray:myArray];

for(id element in uniqueElements) {
  // iterate here
}

Upvotes: 3

Related Questions