Answer the question
In order to leave comments, you need to log in
How to sort a 2D array in Swift?
Let's say there is an array var arr:[(type:Int,name:String)] = []
How to sort it in swift (for example, in ascending order) by one of the fields? For example on the field type:Int?
Answer the question
In order to leave comments, you need to log in
Well, let's start with the fact that this is a one-dimensional array.
arr.sort { (first, second) -> Bool in
return first.type < second.type
}
arr.sort { $0.type < $1.type }
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question