所以我有一个包含大约 180 个字典的数组,每个字典中有 5 个对象(3 个字符串和 2 个 NSNumber)
我正在尝试按其属性之一对每个字典进行排序,这对字符串很好,但是当涉及到数字时,它不能正确排序。
-(void) sortArrayBy:(int)sortingNumber {
switch (sortingNumber) {
case 0:
NSLog(@"sorting by atomicnumber");
[self.elementsArray sortUsingDescriptors:[NSArray arrayWithObjects:
// When sorting this comes back the same each time but not in the correct order
[NSSortDescriptor sortDescriptorWithKey:@"ATOMIC NUMBER" ascending:YES], nil]];
break;
case 1:
NSLog(@"sorting by name");
[self.elementsArray sortUsingDescriptors:[NSArray arrayWithObjects: [NSSortDescriptor sortDescriptorWithKey:@"ELEMENT NAME" ascending:YES], nil]];
break;
case 2:
NSLog(@"sorting by symbol");
[self.elementsArray sortUsingDescriptors:[NSArray arrayWithObjects: [NSSortDescriptor sortDescriptorWithKey:@"CHEMICAL SYMBOL" ascending:YES], nil]];
break;
case 3:
NSLog(@"sorting by mass");
// When sorting this comes back the same each time but not in the correct order
[self.elementsArray sortUsingDescriptors:[NSArray arrayWithObjects: [NSSortDescriptor sortDescriptorWithKey:@"ATOMIC MASS" ascending:YES], nil]];
break;
default:
break;
}