What does "refer to parameters by number instead of by name" in Swift actually does?

Viewed 23

I am new to programming and have learned some basic Python and Java so far. I was hoping to get into Swift so I'm following Apple's Swift Guided Tour. In the section about functions they said

"You can refer to parameters by number instead of by name. A closure passed as the last argument to a function can appear immediately after the parentheses. When a closure is the only argument to a function, you can omit the parentheses entirely. "

Giving an Example as follows:

var numbers = [20, 19, 7, 12]
//...
let sortedNumbers = numbers.sorted {$0 > $1}
print(sortedNumbers)  // "[20, 19, 12, 7]\n"

But if I try numbers.sorted() alone, it will give me the same result.

My question here would be: What exactly is happening in this example code block? Where is the process of executing the program does the lambda function $0 > $1? (I think this function as similar to lambda functions in python but I think I might be wrong) What would be a better example to help me understand this?

0 Answers
Related