I created a NSMutableArray which contains a lot of NSString and float
DataOrder *addClient = [[DataOrder alloc ] initWithName:[[DataOrder instance]product] pric
Also if you didn't create any property/attribute, you can do like:
NSNumber *sum = [anArray valueForKeyPath:@"@sum.floatValue"];
or
float sum = [[anArray valueForKeyPath:@"@sum.floatValue"] floatValue];
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
.
Something like this will work:
float total = 0;
for (DataOrder *client in [[ArrayBuying instance] tableau]) {
total += client.price;
}
NSLog(@"total = %f", total);
I'm just guessing that your DataOrder
class has a price
property. Use what you really have.