求数组的平均值、最大值、最小值、总和
1 NSMutableArray *array = [NSMutableArray arrayWithObjects:@"1",@"5",@"6.8",@"9.2", nil]; 2 float sum = [[array valueForKeyPath:@"@sum.floatValue"] floatValue]; 3 float max = [[array valueForKeyPath:@"@max.floatValue"] floatValue]; 4 float min = [[array valueForKeyPath:@"@min.floatValue"] floatValue]; 5 float avg = [[array valueForKeyPath:@"@avg.floatValue"] floatValue]; 6 NSLog(@"sum=%f\n max=%f\n min=%f\n avg=%f",sum,max,min,avg);
2018-05-31 15:08:50.918941+0800 YCButton[27366:2852035] sum=22.000000 max=9.200000 min=1.000000 avg=5.500000