In Swift, if a closure holds only a single statement, it automatically returns the value returned from that single statement.
This does not feel very natural in all
What about this ... ;)
@discardableResult func StringReturningFunc() -> String {
return "Test String"
}
// Error: Cannot convert the expressions type '() -> $T0' to type 'String'
let closure: () -> () = {
StringReturningFunc()
}
The reason this happens is the shorthand for single line expression closures. There is an implicit 'return' in your closure as it is written.
let closure: () -> () = {
StringReturningFunc()
return
}
Writing it like that should work