My NSArray contains 100, 110, 91, 98, and 87, all NSStrings.
I’d like to sort them to show up in this order: 87, 91, 98, 100, 110.
Instead they are showing up as 100, 110, 87, 91, 98.
I can’t start the array with all ints instead of strings unfortunately. Anyone have any ideas on how to tell if the array contains ONLY numbers from strings, maybe using a for loop? Then I could just convert them all to ints within the array and do the sort that way. Or maybe there is an easy way I am missing?
Let me know if anyone has any ideas.
You can use the
NSNumericSearchoption to the NSString compare function to sort strings numerically. To do this with an NSArray, you will need to write a block or function to call thecompare:options:method.This will also sort numerically if there is a numer within a string, i.e.
"abcd89"will come before"abcd123".