Sorting array by string literal of numbers

We may have stumbled upon strange sorting behaviour of array based on string literal of number where sorting order isn't based on number's value but the alphabetical order.

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! }


It sorted alphabetically based on first character of string. What we want is to sort based on values of number.

// The Workaround

 slots = slots.sorted { $0.indexStr!.localizedStandardCompare($1.indexStr!)  == .orderedAscending }
1 2 14