Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

admanimal

macrumors 68040
Original poster
Apr 22, 2005
3,531
2
I have a data model with two entities: Category and Expense. Category has a to-many relationship to Expense, and Expense has name, date, and amount attributes, and the inverse of the Category relationship. My goal is to calculate the sum of the expenses' amounts in a category for a certain range of dates (e.g. what were the total expenses in March in the Groceries category). The way I currently do this is by filtering the category's NSSet of expenses with a predicate, and then use valueForKeyPath: on the filtered set to compute the sum of the amounts.

Is this really the best way to do it? I don't entirely understand how Core Data handles the expenses property of a category, so I don't know if it actually has to load all of the expenses into memory before filtering the set or what.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.