Which means $ 0.1, $ 0.0, etc. In Swift?

I saw the dictionary data, its meaning is similar to:

var myDict = ["name": "John", "age": 28] 

I see the code as below:

 myDict.flatMap { let a = $0.0 let b = $0.1 ... } 

What does $0.0 mean? What does $0.1 mean? What is the difference between $0 and $0.1 ?

+5
source share
1 answer

$0 is the short name for the first argument passed to close. In this case, when you match the Dictionary , this argument is a tuple, so $0.0 is the key, and $0.1 is the value

For more information on shorthand argument names, see the Swift documentation on closures

+11
source

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


All Articles