I saw a dictionary data, its value is like:
var myDict = ["name": "John",
"age": 28]
I see a code like 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?
$0 is a shorthand name for first argument passed to closure. In this case, as you're mapping a Dictionary, that argument is a tuple - hence $0.0 is a key, and $0.1 is a value
For more info on shorthand argument names, see Swift documentation on closures
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With