Is there a simple way using KVO and collection operators, that I can sum the total value of a NSDictionary like { ID: NSNumber }?
Example:
@{
"my_ID_abcd": @(8),
"my_ID_efgh": @(2),
"my_ID_ijkl": @(3)
}
Would give 13 as a result.
Indeed @count doesn't return what I want, and @sum doesn't work here.. [email protected] neither...
I need to check the sum in a NSPredicate...
Thanks!
A way to do that would be to use a
SUBQUERY(,,)&FUNCTION(,):From what I tried, you can't really chain two operators (ie
@sum&@allValues, so I used aSUBQUERY:Since, you need a "true/false" on the last one, I used a simple comparaison against itself.
And I used
FUNCTIONto build the array of values.That way, in the end, I can call
@sumon it.I'm not very familiar with
SUBQUERY&FUNCTION, maybe the call could be simplified.If you could use
predicateWithBlock:, it would be much simpler though: