NSArray *testArray = [NSArray arrayWithObjects:@"2.0", @"2.3", @"3.0", @"4.0",@"10",nil]; NSNumber *sum1 = [testArray valueForKeyPath:@"@sum.floatValue"]; NSNumber *avg1 = [testArray valueForKeyPath:@"@avg.floatValue"]; NSNumber* max1=[testArray valueForKeyPath:@"@max.floatValue"]; NSNumber* min1=[testArray valueForKeyPath:@"@min.floatValue"]; NSLog(@"%@ %@ %@ %@",sum1,avg1,max1,min1);
得到结果在右下角控制台打印出来: