可能重复:
best way to sort NSArray
Sort an array with special characters - iPhone
您好,
我有数组,其中我将数字存储为字符串。
如何按照交易顺序对此数组进行排序?
答案 0 :(得分:2)
NSArray *sortedArray = nil;
sortedArray = [oldArray sortedArrayUsingFunction:sortArray context:NULL];
NSInteger intSort(id num1, id num2, void *context) {
// OR: float n1 = [num1 floatValue]; etc.
int n1 = [num1 intValue];
int n2 = [num2 intValue];
if (n1 < n2) {
return NSOrderedAscending;
} else if (n1 > n2) {
return NSOrderedDescending;
} else {
return NSOrderedSame;
}
}