Reputation: 329
On sorting an array i get : 1,10,2,3,4,5,6,7,8,9. What went wrong ?
My code was:
NSArray *sortedArray = [optionKeys sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
where optionKeys were: 7,3,8,4,9,5,1,6,2,10
i had also tried CaseInsensitiveCompare: and got the same result.
Upvotes: 0
Views: 93
Reputation: 8488
Check out this answer. You want to do a numeric sort instead of a string sort.
Upvotes: 0
Reputation: 17916
You're doing a string sort rather than a numeric sort. See this answer.
Upvotes: 0
Reputation: 7717
String comparison will place 10 after 1. You'll need to use a number comparison function. This may help: How to let the sortedarrayusingselector using integer to sort instead of string
Upvotes: 1