The easiest way is to use NSCountedSet. You can use [NSCountedSet setWithArray:myArray]to create a counted set of your array, and then you can iterate over the contents of the set to find out the number of each object in the set. Please note that it will not be sorted.
, -hash, , -isEqual:. -compare:, .
, , :
void printCountOfElementsInArray(NSArray *ary) {
NSCountedSet *set = [NSCountedSet setWithArray:ary];
NSArray *objs = [[set allObjects] sortedArrayUsingSelector:@selector(compare:)];
for (id obj in objs) {
NSLog(@"%@: %d", obj, [set countForObject:obj]);
}
}