Sorting an array in ascending order without losing the index Objective-C

Posted by thary on Stack Overflow See other posts from Stack Overflow or by thary
Published on 2010-03-21T22:39:55Z Indexed on 2010/03/21 22:41 UTC
Read the original article Hit count: 329

Hello all, I have an array for instance,

    Array {
    3.0 at Index 0
    2.0 at Index 1
    3.5 at Index 2
    1.0 at Index 4
}

I would like to get sort it in ascending order without losing the index in the first place, like this,

    Array {
    1.0 at Index 4
    2.0 at Index 1
    3.0 at Index 0
    3.5 at Index 2
}

When I sort the array using this,

NSArray *sortedArray = [hArray sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
[knnRecog sortUsingDescriptors:[NSArray arrayWithObject:sortAsc]];

I lose the index. Does anyone know a way to preserve the index after sorting the array? Thanks

© Stack Overflow or respective owner

Related posts about array

Related posts about ascending