应用场景(快速的获取数组最值、平均值)
- (void)valuesAboutArray{
NSMutableArray *array = [NSMutableArray array];
for (int i = 0; i < 10; i++) {
CGFloat num = arc4random() % 100 + 1;
[array addObject:[NSNumber numberWithFloat:num]];
}
CGFloat maxValue = [[array valueForKeyPath:@"@max.floatValue"] floatValue];
CGFloat minValue = [[array valueForKeyPath:@"@min.floatValue"] floatValue];
CGFloat avgValue = [[array valueForKeyPath:@"@avg.floatValue"] floatValue];
}
网友评论