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 Swift Closures Closures in iOS Writing Methods With Closures

How is a parameter and a return type without a body of code considered a closure?

For example, in the getRecentBlogPosts method, we add a completion parameter of type (NSURLResponse! -> Void), but how exactly is this considered a closure? I thought they needed a body of code afterwards.

1 Answer

Rashii Henry
Rashii Henry
16,433 Points

I know this concept can be a bit confusing but once you notice that when you write a function. after you declare the return there are a set of brackets that follow the return.

Thoses brackets are the block of code that qualifies a function as a closure. Whether it's empty or not its syntax is read by the compiler as a block of code, function, or closure. Use those terms pretty loosely. Hopes this helps bro!