As @TheBasicMind said in his answer, you have an array of strings, not an array of integers. You are sorting your strings in character-by-character order, not numeric order.
Basic mind's solution of using an array of NSNumbers is probably the better solution, since it stores an array of numeric values rather than array of strings that represent numeric values.
Another solution would be to rewrite your sort code to use a string sort that uses the numeric value of your strings:
NSArray *array = @[@"12", @"7", @"10", @"3", @"4", @"5",
@"6", @"1", @"8", @"9", @"2", @"11"];
NSArray *sortedArray = [array sortedArrayUsingComparator: ^NSComparisonResult(
NSString *string1,
NSString *string2) {
return [string1 compare: string2 options: NSNumericSearch];
}];
NSLog(@"Sorted array = %@", sortedArray);
That yields the following output:
Sorted array = (
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12
)