我有数量字符串值,如 1000、100000、10000000、5000。问题是使用排序描述符进行排序。它以正确的方式排序,但在转换为 1k、10k、1m、5k 后它不起作用,请告诉我你的建议
这是我的源代码
[m_sortTempArray sortUsingComparator:^NSComparisonResult(id obj1, id obj2) {
NSDictionary *dict1 = obj1;
NSDictionary *dict2 = obj2;
NSString *string1 = nil;
NSString *string2 = nil;
if (1)
{
if ([[dict1 objectForKey:@"kpiData"] count]>0 && [[dict2 objectForKey:@"kpiData"] count]>0) {
string1 = [[[dict1 objectForKey:@"kpiData"] objectAtIndex:kIndex] objectForKey:@"kpiActual"];
string2 = [[[dict2 objectForKey:@"kpiData"] objectAtIndex:kIndex] objectForKey:@"kpiActual"];
} else {
//return 0;
string1=@"0";
string2=@"0";
}
}
if ([string2 isEqualToString:@""]){
string2 = @"0";
}
if ([string1 isEqualToString:@""]){
string1 = @"0";
}
if ([string1 integerValue] > [string2 integerValue] ) {
return (NSComparisonResult)NSOrderedAscending;
}
if ([string1 integerValue] < [string2 integerValue] ) {
return (NSComparisonResult)NSOrderedDescending;
}
return (NSComparisonResult)NSOrderedSame;
}];