NSArray *testArray = [NSArray arrayWithObjects:@"-2.0", @"2.3", @"3.0", @"4.0", nil];
//获取数组各元素和
NSNumber *sum = [testArray valueForKeyPath:@"@sum.floatValue"];
//获取平均值
NSNumber *avg = [testArray valueForKeyPath:@"@avg.floatValue"];
//获取数组中的最大值
NSNumber *max = [testArray valueForKeyPath:@"@max.floatValue"];
//获取数组中最小值
NSNumber *min = [testArray valueForKeyPath:@"@min.floatValue"];
网友评论