Sort an array of string containing numbers
byBy default, Sorting an array of string containing numbers is not sorted in natural order of numbers. They are sorted in natural order of string characters.
For example objects in array have property of type string which are all literal of numbers:
slot1.indexStr = “1”
slot2.indexStr = “14”
slot3.indexStr = “2”
slots = [slot1, slot2, slot3]
slots = slots.sorted { $0.indexStr! < $1.indexStr! }
1
14
2
It sorted alphabetically based on first character of string. What we want is to sort based on values of number.