Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Closures in Swift Closure Expressions Closure Expression Syntax

Passing in the constant rather than the function name ?

Hi,

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,561 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.