Basically I need a function which counts the amount of different values in an array and one other function to give me the actual count of each different value in my array.
I have an Array which contains a changing amount of values:
Array = (This, This, This, This, Is, Is, Is, Is, Is, It, It, It, It)
I want to make a list view, each section should contain the different categories like:
This
- Element 1
- Element 2
- ...
Is
- Element 1
- ...
It
- Element 1
- ...
So I need the number 3 for my number of sections and the number of child-elements for each section.
How can I achieve that? Is there a better way than a for-statement with counting indexes for each section?
Thank you!
Add each array element to an
NSCountedSet. Then thecountof the set is the number of distinct objects you added, and you can usecountForObject:to ask the set how many there are of each distinct object.