NSArray *tempArray = [NSArray arrayWithObjects:@"2", @"3", @"4",@"5", @"10", nil];
NSNumber *sum = [tempArray valueForKeyPath:@"@sum.floatValue"];
NSNumber *avg = [tempArray valueForKeyPath:@"@avg.floatValue"];
NSNumber *max = [tempArray valueForKeyPath:@"@max.floatValue"];
NSNumber *min = [tempArray valueForKeyPath:@"@min.floatValue"];
NSLog(@"sum %@ avg %@ max %@ min %@", sum, avg, max, min);
运行结果:
屏幕快照 2017-08-14 下午4.27.23.png
网友评论