在我的NSMutableArray
我有这些需要排序的值,
+0.00,
+0.00,
+0.00,
+0.10,
+0.21,
+3.04,
+3.45,
+3.56,
+4.87,
+5.01,
+5.05,
+5.40,
+6.07,
+6.57,
+6.71,
+7.54,
+7.58,
+8.11,
+8.94,
+9.42,
+9.49,
9.78,
-1.69,
-1.80,
-10.99,
-12.72,
-2.30,
-2.64,
-2.64,
-3.12,
-4.59,
-5.11,
-5.83,
-6.54,
-6.64
我的排序代码,
NSSortDescriptor * frequencyDescriptor = [[NSSortDescriptor alloc] initWithKey:ytd
ascending:YES];
id obj;
NSEnumerator * enumerator = [array objectEnumerator];
while ((obj = [enumerator nextObject])) NSLog(@"%@", obj);
NSArray * descriptors = [NSArray arrayWithObjects:frequencyDescriptor, nil];
NSArray * sortedArray = [array sortedArrayUsingDescriptors:descriptors];
NSLog(@"\nSorted ...");
enumerator = [sortedArray objectEnumerator];
while ((obj = [enumerator nextObject])) NSLog(@"%@", obj);
我得到的输出,
2013-09-17 13:00:28.315 Pondo MF[1275:c07] +0.00
2013-09-17 13:00:28.316 Pondo MF[1275:c07] +0.00
2013-09-17 13:00:28.316 Pondo MF[1275:c07] +0.00
2013-09-17 13:00:28.316 Pondo MF[1275:c07] +0.10
2013-09-17 13:00:28.317 Pondo MF[1275:c07] +0.21
2013-09-17 13:00:28.317 Pondo MF[1275:c07] +0.34
2013-09-17 13:00:28.317 Pondo MF[1275:c07] +0.68
2013-09-17 13:00:28.317 Pondo MF[1275:c07] +1.35
2013-09-17 13:00:28.318 Pondo MF[1275:c07] +18.59
2013-09-17 13:00:28.318 Pondo MF[1275:c07] +3.04
2013-09-17 13:00:28.318 Pondo MF[1275:c07] +3.45
2013-09-17 13:00:28.319 Pondo MF[1275:c07] +3.56
2013-09-17 13:00:28.319 Pondo MF[1275:c07] +4.87
2013-09-17 13:00:28.319 Pondo MF[1275:c07] +5.01
2013-09-17 13:00:28.319 Pondo MF[1275:c07] +5.05
2013-09-17 13:00:28.320 Pondo MF[1275:c07] +5.40
2013-09-17 13:00:28.320 Pondo MF[1275:c07] +6.07
2013-09-17 13:00:28.320 Pondo MF[1275:c07] +6.57
2013-09-17 13:00:28.320 Pondo MF[1275:c07] +6.71
2013-09-17 13:00:28.321 Pondo MF[1275:c07] +7.54
2013-09-17 13:00:28.321 Pondo MF[1275:c07] +7.58
2013-09-17 13:00:28.321 Pondo MF[1275:c07] +8.11
2013-09-17 13:00:28.322 Pondo MF[1275:c07] +8.94
2013-09-17 13:00:28.322 Pondo MF[1275:c07] +9.42
2013-09-17 13:00:28.322 Pondo MF[1275:c07] +9.49
2013-09-17 13:00:28.322 Pondo MF[1275:c07] +9.78
2013-09-17 13:00:28.323 Pondo MF[1275:c07] -1.69
2013-09-17 13:00:28.323 Pondo MF[1275:c07] -1.80
2013-09-17 13:00:28.323 Pondo MF[1275:c07] -10.99
2013-09-17 13:00:28.323 Pondo MF[1275:c07] -12.72
2013-09-17 13:00:28.324 Pondo MF[1275:c07] -2.30
2013-09-17 13:00:28.324 Pondo MF[1275:c07] -2.64
2013-09-17 13:00:28.324 Pondo MF[1275:c07] -2.64
2013-09-17 13:00:28.324 Pondo MF[1275:c07] -3.12
2013-09-17 13:00:28.325 Pondo MF[1275:c07] -4.59
2013-09-17 13:00:28.325 Pondo MF[1275:c07] -5.11
2013-09-17 13:00:28.325 Pondo MF[1275:c07] -5.83
2013-09-17 13:00:28.326 Pondo MF[1275:c07] -6.54
2013-09-17 13:00:28.326 Pondo MF[1275:c07] -6.64
这是不正确的,因为排序数组应该从+18.59
第一个值开始。我的代码哪里出错了?任何修复它的指针?