Can someone explain why the swift compiler complains about the \"offset:\" parameter which is optional anyway?
If I pass zero as param incrementByFive(0)
Only functions can have default parameters in Swift, but not closures.
The closure returned from makeIncrementer()
has the type
(Int?) -> Int
, i.e. it takes one argument of type Int?
,
and that must be provided when calling the closure.
Compare also SR-531 Allow default parameters in closure parameters, in particular the comment
Doesn't really make sense, if you need this behavior you should be using a function. Closures are usually called anonymously with their arguments all provided, so there is no need for default parameter values.