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 trialjames bunn
2,377 PointsIf 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
2,377 PointsThanks 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
2,377 PointsThanks 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
21,046 PointsEverything 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.
Steven Deutsch
21,046 PointsSteven Deutsch
21,046 PointsYou should read the chapter on Closures in the Swift Language Guide. https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Closures.html#//apple_ref/doc/uid/TP40014097-CH11-ID94