1.数组求和;平均值;最大值;最小值
NSArray *array = [NSArray arrayWithObjects:@"2.0", @"2.3", @"3.0", @"4.0", @"10", nil];
CGFloat sum = [[array valueForKeyPath:@"@sum.floatValue"] floatValue];
CGFloat avg = [[array valueForKeyPath:@"@avg.floatValue"] floatValue];
CGFloat max =[[array valueForKeyPath:@"@max.floatValue"] floatValue];
CGFloat min =[[array valueForKeyPath:@"@min.floatValue"] floatValue];
NSLog(@"%f\n%f\n%f\n%f",sum,avg,max,min);
2.可变数组不能存入int类型?
数组只能存放指针,你可以把int转为number,
a.
NSMutableArray *array = [NSMutableArray array];
for (NSInteger i= 0; i < 10; i++) {
[array addObject:@(i)];
}
b.
[NSString stringWithFormat:@"%d",xxxx],再加入数组如果要输出显示的话 就用NSString可以了
c.
NSUInteger转换为NSNumber可以通过NSNumber *aNumber = [NSNumber numberWithInteger:21];来转换,然后把NSNumber放到数组里
最后要用数据的时候,把NSNumber从数组里取出来,然后通过NSInteger anInteger = [aNumber integerValue];拿到那个数字21
3.