iiFreeman
iiFreeman

Reputation: 5175

complex NSFetchRequest with groupBy

I feel really stuck with this task, maybe somebody can suggest me a way to achieve this:

CoreData model

EKEvent <<---> EKCategory

EKEvent has properties: NSDate *created; and NSNumber *amount;

I need to fetch EKEvent objects with predicate like:

[NSPredicate predicateWithFormat:@"((created >= %@) AND (created <= %@))", self.fromDateFilterValue, self.toDateFilterValue];

and also it should be grouped by their categories (event has to-one relationship to category) cause I need to represent only categories in UITableView and show [email protected] of fetched events for each category in UITableViewCells.

the question is how do I construct my NSFetchRequest to get results which contains NSDictionary objects with: 1. EKCategory object (on maybe some field of this category, like .title and .iconImageName) 2. summ for all .events inside this category, confirm to passed NSPredicate 3. array of EKEvent objects confirmed to passed NSPredicate

Upvotes: 0

Views: 151

Answers (1)

Wain
Wain

Reputation: 119031

From your comment above: exactly.

Get the categories, fetching or however you want. Then, from each category, get the set of events from the relationship. Filter that set of events using your predicate. Then use the array KVC operator to get the sum of the remaining events.

Upvotes: 1

Related Questions