ios - How get the total sum of float from a NSMutableArray

后端 未结 3 958
孤城傲影
孤城傲影 2021-01-27 21:48

I created a NSMutableArray which contains a lot of NSString and float

DataOrder *addClient = [[DataOrder alloc ] initWithName:[[DataOrder instance]product] pric         


        
3条回答
  •  感动是毒
    2021-01-27 22:13

    Key-Value coding:

    NSNumber *sum = [[[ArrayBuying instance] tableau] valueForKeyPath:@"@sum.price"];
    

    gives the sum of the "price" attribute of all the objects in the array.

    To make this work with your custom objects, price should be a property of DataOrder.

提交回复
热议问题