extension Int {
func repetitions(task: () -> ()) {
for i in 0..<self {
task()
}
}
}
I know that the task is parameter namer. But I do not know what () -> ().
This means that success parameter is a function that receives an object (AnyObject) and returns nothing (Void). Follow this answer to receive notifications. edited Dec 10, 2020 at 18:11.
To me, the arrow represents a mapping which I think is really appropriate and natural for functions (or more generally closures) just as it is used in Swift.
$0 and $1 are closure's first and second Shorthand Argument Names (SAN for short) or implicit parameter names, if you like. The shorthand argument names are automatically provided by Swift. The first argument is referenced by $0 , the second argument is referenced by $1 , the third one by $2 , and so on.
An autoclosure is a closure that's automatically created to wrap an expression that's being passed as an argument to a function. It doesn't take any arguments, and when it's called, it returns the value of the expression that's wrapped inside of it.
() -> ()
just means Void -> Void
- a closure that accepts no parameters and has no return value.
More precisely, () -> ()
means a closure taking a tuple with 0 values as argument and returning a tuple with zero values. Which is equivalent to saying: a closure taking no arguments and with no return value (or returning void
)
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