I’m using NSXMLParser to fetch a feed, and am sorting the resulting array according to various properties. Result of parse is a bunch of NSStrings. Everything is working fine, except of course the one string with numbers greater than 10 in it. Array ends up getting ordered like so:
9,8,7,6,5,4,3,2,1,12,11,10,0
Obviously I want it like so:
12,11,10,9,8,7,6,5,4,3,2,1,0
I’m assuming this is because NSStrings get sorted “alphabetically”, and that I’m going to have to convert to NSNumber or something like it? Is this the best way, or is there something simpler?
I currently have:
if ([elementname isEqualToString:@"rankicon"])
{
currentPlayer.rankicon = currentNodeContent;
}
and then:
NSSortDescriptor *rankDescriptor =
[[[NSSortDescriptor alloc]
initWithKey:@"rankicon"
ascending:NO]autorelease];
NSArray *sortDescriptors =
[NSArray arrayWithObjects:rankDescriptor, nil];
[players sortUsingDescriptors:sortDescriptors];
This should work in your case (adding selector as parameter with value localizedStandardCompare) –