在NSMutableArray中查找重复值

时间:2012-05-25 18:29:35

标签: iphone xcode indexing nsmutablearray duplicates

如何知道重复出现在我的数组中的次数?

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

{ 

     NSDictionary *dico = [myArray objectAtIndex:index ];

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

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

这是我的NSLog:

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

想知道我的重复值在哪里。

THX

1 个答案:

答案 0 :(得分:3)

如果我没错,NSSet就是为了这个而设计的...... 试试这个..

NSSet *uniqueElements = [NSSet setWithArray:myArray];

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