I'm just getting through tons of research and tutorials on ios app development. Making my first app now and using array with tableviews. My question is now that I have populated arrays with custom objects, I want to query it. Group By with Sum... things of that nature.
In my research I've found predicates for some types of filtering. So far I have successfully returned a new array where on property in my class is equal to "x". Predicate worked for that part.
But I'm not sure how to expand to groupby/sum. I've been reading core data might accomplish this but is probably overkill.
Can someone please help me out with some options to research?
Thanks!!!
example Person Class name age salary
how can I group by name, and at the same time sum up the salaries?
I found this also ... is this an efficient way to tackle problem
// Get all the airline names with no duplicates using the KVC @distinctUnionOfObjects collection operator
NSArray *airlineNames = [arrayMealRating valueForKeyPath:@"@distinctUnionOfObjects.Airline"];
// Loop through all the airlines
for (NSString *airline in airlineNames) {
// Get an array of all the dictionaries for the current airline
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(Airline == %@)", airline];
NSArray *airlineMealRating = [arrayMealRating filteredArrayUsingPredicate:predicate];
// Get the sum of all the ratings using KVC @sum collection operator
NSNumber *rating = [airlineMealRating valueForKeyPath:@"@sum.Rating"];
NSLog(@"%@: %@", airline, rating);
}
@sum: stackoverflow.com/questions/11927151/…NSPredicatedoesn't support grouping. That said you can useNSFetchedResultsControllerin conjunction with CoreData and anNSPredicateto provide grouping as well as dynamic table management. Look around for some tutorials, Ray Wanderlich's site is a reliable source.