Search code examples
iosobjective-cnsarraynsdictionary

How to find sum of all objects for some key in array of dictionaries?


I have an Array of Dictionaries.

NSArray *myDicionariesArrey = ( object 1: { keyToCulc: 30 } , object 2: { keyToCulc: 40 } )

How to find sum of all objects for keyToCulc key in the array, with simple command?
(30 + 40 = 70)


Solution

  • int sum = [myDicionariesArrey valueForKeyPath:@"@sum.keyToCulc"];
    

    NB: Untested, written from memory.