I have an array full of strings with each string being a name. Some names may be the same while some may be different. The language I’m working in is objective-C. I want to be able to find out which name is most popular from this array (the array will be dynamic based on information given to the app from the user). I am not sure how to make this happen EFFICIENTLY. If someone could expand on this or provide an example, it would be appreciated.
Thank you
Example:
NSArray *nameArray= [[NSArray alloc] initWithObjects @"james", @"megan", @"lauren", @"mike" @james", nil];
//james would be the most popular name
Use
NSCountedSetand then find the object with highest count usingcountForObject:method.Checking the result:
Credit goes to @Evan Mulawski answer