I am trying to sort an array by the most common value of a property or attribute. This question and others suggest you can do this efficiently using an NSSet. However, it is merely sorting by most common string, not values of a property within custom objects. How would I get the following to return the most popular title?
NSArray<Articles*> *results = [self.managedObjectContext executeFetchRequest:fetchRequest
error:&error];
NSCountedSet* mySet = [[NSCountedSet alloc] initWithArray:results];
Articles* mostRead = nil;
NSUInteger highestCount = 0;
for(Articles* article in results) {
NSUInteger count = [mySet countForObject:article.title];
if(count > highestCount) {
highestCount = count;
mostRead = article;
}
}
The above code is not returning a value as countForObject:article.title does not seem to be recognized.