Using Core Data, I encountered a problem. I have an entity “Movement” with an attribute “amount”. How do I make the sum of all the “amount” of all instances? I’d like to understand how to use NSExpressionDescription, but it’s good enough NSSet.
Using Core Data , I encountered a problem. I have an entity Movement with
Share
Having a managedObjectContext:
We create a fetch request with return type dictionary:
Then we create an expression description to calculate the sum:
Set the request properties to fetch:
We could also set a predicate if we want.
And last we execute the request and get an array containing a dictionary with one key(@”sumOfAmounts”) and its value is a NSNumber with the sum of amounts.
Cheers