我有一个NSNumbers的NSArray,想要找到数组中的最大值。有没有内置的功能可以做到这一点?我正在使用iOS4 GM,如果这有什么不同的话。
发布于 2010-06-21 03:39:30
KVC方法如下所示:
int max = [[numbers valueForKeyPath:@"@max.intValue"] intValue];
或
NSNumber * max = [numbers valueForKeyPath:@"@max.intValue"];
将数字作为NSArray
发布于 2016-03-13 02:48:21
NSArray * test= @[@3, @67, @23, @67, @67];
int maximumValue = [[test valueForKeyPath: @"@max.self"] intValue];
NSLog(@" MaximumValue = %d", maximumValue);
// Maximum = 67
发布于 2017-11-03 13:35:46
希望对你有帮助。
NSArray * arrayOfBarGraphValues = @[@65, @45, @47 ,@87 , @46, @66 ,@77 ,@47 ,@79 ,@78 ,@87 ,@78 ,@87 ];
int maxOfBarGraphValues = [[arrayOfBarGraphValues valueForKeyPath: @"@max.self"] intValue];
NSLog(@" MaximumValue Of BarGraph = %d", maxOfBarGraphValues);
https://stackoverflow.com/questions/3080540
复制相似问题