0

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

2
  • Do you want to eliminate the duplicates or just count how many times a name appears on your array? Commented May 25, 2012 at 18:37
  • hi want to delete them but need to keep one Commented May 25, 2012 at 19:03

1 Answer 1

3

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
}
Sign up to request clarification or add additional context in comments.

1 Comment

for (id element in [NSSet setWithArray:myArray]) {}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.