iOS Closures in Swift Closure Expressions Closure Expression Syntax

Passing in the constant rather than the function name ?


I am wondering why it is that you pass the constant doubleFunction rather than the function name double within the inline closure ?

1 Answer

Addison Francisco
Addison Francisco
9,524 Points

I believe he is trying to expand on functions being “first class citizens” in this example, which is why he did a round about implementation by first assigning a function to a constant. You are correct in saying that you could instead pass the literal function name into the closure to achieve the same result. He is just trying to expound on how functions and closures work in a wholistic way to help students understand what is going on with closures. A lot of his lessons will show you how to achieve the same result by working out multiple approaches.