0

I know this has been asked in a java question. But how can I could in Objective-C count how many times a string appears in an array? For example, (please excuse the faux code here) if I had an array like...

index 0 : "Andy"
index 1 : "Paul"
index 2 : "Paul"
index 3 : "Michael"
index 4 : "Paul"
index 5 : "Andy"

How would I perform operations on this array to calculate the number of times each word is present within the array? Like logging out...

Michael = 1
Andy = 2
Paul = 3 
Tom Testicool
  • 563
  • 7
  • 26
  • 1
    [NSCountedSet](https://developer.apple.com/library/mac/documentation/cocoa/reference/foundation/classes/NSCountedSet_Class/Reference/Reference.html) – Bryan Chen Jun 30 '14 at 03:51
  • See this example for NSCountedSet : http://stackoverflow.com/questions/7605543/nscountedset-get-count-of-items-in-set – CRDave Jun 30 '14 at 03:53
  • Thank you for the response. And while that does answer the majority of my problems, there is a complication that arrises from the method in your link. What I am trying to do is populate an interactive pie chart with the values of an array. Do you know how I can get the product of the NSCountedSet method back into an array to use in my pie chart? – Tom Testicool Jun 30 '14 at 15:01

0 Answers0