话不多说直接上代码,省去了一大堆的遍历代码,看着爽多了
- (void)viewDidLoad {
[super viewDidLoad];
NSArray *array= [NSArray arrayWithObjects:@"2.0",@"2.3",@"3.0",@"4.0",@"10",nil];
CGFloat max =[[array valueForKeyPath:@"@max.floatValue"] floatValue];
CGFloat min =[[array valueForKeyPath:@"@min.floatValue"] floatValue];
CGFloat sum = [[array valueForKeyPath:@"@sum.floatValue"] floatValue];
CGFloat avg = [[array valueForKeyPath:@"@avg.floatValue"] floatValue];
NSLog(@"最大数 = %f,最小值 = %f,和 = %f,平均数 = %f", max, min, sum, avg);
}