gpt4 book ai didi

ios - iOS应用中的排序数组问题

转载 作者:行者123 更新时间:2023-12-01 17:42:02 25 4
gpt4 key购买 nike

我有一个像这样的数组:

(
“8461.86”,“8468.22”,“8468.22”,“8162.59”,“8164.50”,“7280.59”)

我尝试按照以下顺序递减排序此数组:

sortedArray = [arr_distance sortedArrayUsingComparator:^(id firstObject, id secondObject) {
return [((NSString *)firstObject) compare:((NSString *)secondObject) options:NSNumericSearch];
}];

但是我得到如下数组:

(
“7280.59”,“8162.59”,“8164.50”,“8461.86”,“8468.22”,“8468.22”)

为什么会这样?

我也喜欢
return [firstObject compare:secondObject options:NSNumericSearch];

但是没有得到正确的排序数组。

最佳答案

NSSortDescriptor *desc = [[NSSortDescriptor alloc]initWithKey:@"" ascending:NO];
NSMutableArray *yourTempArray = [[NSMutableArray alloc]initWithObjects:@"8459.93",@"8466.28",@"8466.28",@"8160.70",@"8162.61",@"7278.56", nil];
[yourTempArray sortUsingDescriptors:[NSArray arrayWithObject:desc]];
NSLog(@"sotedAr == %@",yourTempArray);

输出:
sotedAr == (
"8466.28",
"8466.28",
"8459.93",
"8162.61",
"8160.70",
"7278.56"

)

关于ios - iOS应用中的排序数组问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16030104/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com