I have an array of strings from an online database that I trying to determine the most commonly used word. The values inside the arrays will vary but I want to check the most co
Simplest way is probably NSCountedSet
:
NSCountedSet* stringSet = [[NSCountedSet alloc] initWithArray:strings];
NSString* mostCommon = nil;
NSUInteger highestCount = 0;
for(NSString* string in stringSet) {
NSUInteger count = [stringSet countForObject:string];
if(count > highestCount) {
highestCount = count;
mostCommon = string;
}
}