I have an NSArray of data objects Books retrieved from Core Data.
For one of the attributes or variables in core data, rating, I would like to find its max.
I am able to get an array of ratings as follow:
NSMutableArray *ratingsArray = [theBooks valueForKeyPath:@"rating"];
NSLog(@"ratingsArray%@",ratingsArray);//this logs fine
However, I am stuck on how to get the max.
_maxRating = [ratingsArray valueForKeyPath:@"@max.rating.self"];
builds but gives an error at runtime:
this class is not key value coding-compliant for the key rating.'
(Adding to my confusion, I have read that an array should not be able to hold a float, however, mine does to the degree that I can log out the ratings in the above code fine. Rating is a float value in the NSManaged Object Class and also in the core data model. It is originally retrieved from an API as a string, and converted to a float prior to storage in core data using [ratingString floatValue]
)
What is the correct way to get the max for an attribute in an array of objects?