Swift 3 sorts an array of tuples

I found these answers:

Sorting an array of tuples in swift 3 How to sort an array of tuples?

But I still have problems. Here is my code:

var countsForLetter:[(count:Int, letter:Character)] = []
...
countsForLetter.sorted(by: {$0.count < $1.count})

Swift 3 wanted me to add: and now it says that the result of sorting the: by call is not used.

I'm new to quick 3. Sorry if this is the main question.

+4
source share
2 answers

You get this warning because it sorted(by...returns a new, sorted version of the array you are calling it on. Therefore, a warning indicates that you are not assigning it to a variable or anything else. You could say:

countsForLetter = countsForLetter.sorted(by: {$0.count < $1.count})

, " ", sorted(by sort(by, countsForLetter .

+7

Sorted() , .

:

countsForLetter  = countsForLetter.sorted(by: {$0.count < $1.count})

countsForLetter.sort(by: {$0.count < $1.count})
+2

Source: https://habr.com/ru/post/1671313/


All Articles