How to sort numbers in array from low to high

Posted by Louie on Stack Overflow See other posts from Stack Overflow or by Louie
Published on 2010-12-28T23:32:51Z Indexed on 2010/12/28 23:53 UTC
Read the original article Hit count: 182

Filed under:
|
|

Hello all,

I am trying to sort an array of prices from low to high. I have it working but not the way I want it to. Long story short, the sorter is putting numbers in order like this: 100 10900 200 290

instead of sorting like this

100 200 290 10900

here is my code I am doing this with.

-(void)filterPriceLowHigh {

        NSSortDescriptor *sortDescriptor;

        sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"ListPrice"

                                                      ascending:YES] autorelease];

        NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];

        NSArray *sortedArray;

        sortedArray = [app.vehiclesArrayToDisplay sortedArrayUsingDescriptors:sortDescriptors];

        [app.vehiclesArrayToDisplay removeAllObjects];

        [app.vehiclesArrayToDisplay addObjectsFromArray:sortedArray];


}

Could someone tell me what I need to do here? thanks in advance.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about SDK