SAdams SAdams - 2 months ago 7
iOS Question

iOS Sum values in Table View without core data

Is there a way to sum the values entered into a table view cell without using Core Data? I am currently using Parse. I guess a better question would be how can I get the sum using Parse? I'm really scratching my head on this one. Hand holding may be required.

Answer

You can probably use the Key-Value Coding collection operators. Suppose the row data for the table are a bunch of instances of class Entry and are collected in an NSArray named data. Further suppose each Entry object has an NSNumber property named cost and this is what you want to sum. Then you can do so as follows:

NSNumber *sum = [data valueForKeyPath:@"@sum.cost"];

Just to be clear: this does require that the values you wish to sum are properties of the objects that are backing each row.