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 Using a Closure

james bunn
james bunn
2,377 Points

If the completion parameter is a closure, why doesn't it implement brackets around the parameters

From the earlier courses, when defining a closure, we always used brackets around the parameters. If the "completion" parameter is a closure, why doesn't it implement brackets

e.i { (parameters) -> return type in Statements }

For example. completion: { ([String:AnyObject]?) -> ()) }

james bunn
james bunn
2,377 Points

Thanks Deutsch, I reviewed the additional documents and unfortunately, I'm still at a loss for understanding how a completion handler qualifies as a closure. The "Swift Closures and Functions" doesn't explain why we don't need the curly braces when specifying a completion handler. The "Completion Handlers" document briefly mentions the use of a completion handler, but doesn't elaborate on why a completion handler qualifies as a closure.

I may be a bit hard headed on this, but just looking for a clean explanation on how the completion handler qualifies as a closure and why the syntax doesn't require a curly brace.

1 Answer

james bunn
james bunn
2,377 Points

Thanks Deutsch. I read this section multiple times and I'm still having difficulty. Is there a particular section of the Closure chapter you'd recommend?

Steven Deutsch
Steven Deutsch
21,046 Points

Everything up to Closures are Reference Types. This doesn't mean the entire chapter isn't important though. Here's some more reading if you want.

  1. Swift Closures and Functions
  2. Completion Handlers