Reputation: 3636
I have an NSMutableArray with some NSNumber :
{1, 2, 3, 3, 2, 1, 6, 2}
I would like to know how many occurrence of each number appears in the list.
Ex :
1 = 2
2 = 3
3 = 2
6 = 1
Upvotes: 0
Views: 685
Reputation: 130200
You can put all the items into a NSCountedSet
.
NSCountedSet* countedSet = [[NSCountedSet alloc] initWithArray:array];
for (NSNumber* number in countedSet) {
NSLog(@"%@ = %u", number, [countedSet countForObject:number]);
}
Upvotes: 11