I want to know that how can we use sort
or sorted
function for multidimensional array in Swift?
For example theirs an array:
I think you should use an array of tuples, then you won't have any problems with type casts:
let array : [(Int, String)] = [
(5, "test123"),
(2, "test443"),
(3, "test663"),
(1, "test123")
]
let sortedArray = array.sorted { $0.0 < $1.0 }
Swift is all about type safety
(Change sorted
to sort
if you're using Swift 2.0)