I have some data like this :
1, 111, 2, 333, 45, 67, 322, 4445
NSArray *array = [[myData allKeys]sortedArrayUsingSelector: @selector(compare:)];
If I run this code, it sorted like this:
1, 111, 2,322, 333, 4445, 45, 67,
but I actually want this:
1, 2, 45, 67, 111, 322, 333, 4445
How can I implement it? thz u.
Expanding on Paul Lynch’s answer, here’s an example I have doing exactly this using a comparison method as a category on
NSString. This code handles only the case of numbers followed by optional non-numeric qualifiers, but you could extend it to handle cases like “1a10” etc. if desired.Once you create the category method, you just need to do
[[myData allKeys]sortedArrayUsingSelector:@selector(psuedoNumericCompare:)];