NSPredicate from choosing master data by object identifier (and potential summation)

I find my way to an advanced piece of master data. I know that this is not SQL, and there are limitations, however, how would I translate the code below to NSPredicate, which will be applied in the fetch request?

Product* p = self.product; //this is a managed object double vol=0; for (PlanningItem* pi in self.planitems) { if (pi.product==p) vol+=pi.volume; 
  • I want to get all the elements of the plan that have p as their product.
  • Next, I want to summarize all the volumes in this set.

How to make 1 in a fetch request using NSPredicate? Can I do 2 at the same time?

I am asking for a line for NSPredicate. I can build Fetchrequest myself.

Tx!

+4
source share
1 answer
 // Create the predicate NSPredicate *productPredicate = [NSPredicate predicateWithFormat:@"(product == %@)", product]; // Apply the predicate to your FetchRequest [fetchRequest setPredicate:productPredicate]; 
+11
source

All Articles