I have seen closures in swift have $0 inside of it and sometimes they use $1. What exactly is $0 and what are other $x can you use?
Here are examples of it in use.
applyMutliplication(2, {$0 * 3})
array.map({$0 + 1})
Thanks!
I have seen closures in swift have $0 inside of it and sometimes they use $1. What exactly is $0 and what are other $x can you use?
Here are examples of it in use.
applyMutliplication(2, {$0 * 3})
array.map({$0 + 1})
Thanks!
It's a shorthand argument name.
From the Swift Book:
It helps reduce the verbosity of your code (sometimes at the cost of readability), so you don't have to write out long argument lists when defining closures.