NSArray *array = [NSArray arrayWithObjects:@"1.2",@"2.1", @"4.9", nil];// 最大值CGFloat maxFloat = [[array valueForKeyPath:@"@max.floatValue"] floatValue];// 最小值CGFloat minFloat = [[array valueForKeyPath:@"@min.floatValue"] floatValue];// 平均值CGFloat avg = [[array valueForKeyPath:@"@avg.floatValue"] floatValue];// 转为int类型后再转为string类型NSArray *resultArray = [array valueForKeyPath:@"intValue.stringValue"];// 转为int类型后再转为string类型再求每个string的长度NSArray *lengthArray = [array valueForKeyPath:@"intValue.stringValue.length"];NSArray *stringArray = [NSArray arrayWithObjects:@"NameS",@"CHEN", @"WoShiShui", nil];// string数组转大写NSArray *resultArray = [stringArray valueForKeyPath:@"uppercaseString"];
复制代码
KVC计算平均值,最大值,最小值等
最新推荐文章于 2022-05-04 00:00:00 发布