Swift automatically provides "Shorthand Argument", an anonymous argument to "$", only inside inline closures without declaring parameters
You declared a function that received param1 and param2. You can use it to send your function as a Block or add a closure. See the example below:
Your function announcement:
func function (param1 : Int, param2 : Int) -> Int { return param1 + param2 }
Call close function
func getSum(sumFunction:(Int, Int) -> (Int)) -> (Int) { return sumFunction(3,5) }
Using three possibilities:
getSum(sumFunction: function) getSum { (param1, param2) -> (Int) in return param1 + param2 } getSum { return $0 + $1 }
In the last getSum you have built-in closures without declaring parameters, only here you can use for $ 0 ..
$ - refer to the values ββof the closure arguments with the names $ 0, $ 1, etc.
$ 0 = param1, $ 1 = param2
source share