-1

Possible Duplicates:
best way to sort NSArray
Sort an array with special characters - iPhone

Hello,
I have array in which i have numbers stored as string.
How to sort this array in acsending order?

Community
  • 1
  • 1
dks1725
  • 1,631
  • 1
  • 20
  • 29

1 Answers1

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;
    }
}
adam
  • 22,404
  • 20
  • 87
  • 119