iOS 中通过kvc 获取数组的均值、求和、最大最小值等

NSArray *values = @[@72, @78, @75, @70, @72, @73, @77, @78, @75, @70, @72, @73, @87, @78, @75, @70, @72];

NSNumber *avg = [values valueForKeyPath:@"@avg.self"];

NSNumber *sum = [values valueForKeyPath:@"@sum.self"];

NSNumber *max = [values valueForKeyPath:@"@max.self"];

NSNumber *min = [values valueForKeyPath:@"@min.self"];

 

posted @ 2019-11-13 15:32  走路蹩脚的火星人  阅读(400)  评论(0编辑  收藏  举报