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
mattlebl
10,849 PointsCan the "() -> Void in" in a Swift closure be omitted?
I've seen closures which look like this
{
// code
}
work just fine, but in most closures written in Treehouse courses closures always have empty parameters and empty return type, like so
{ () -> Void in
// code
}
Can anyone clarify? We're not passing in any parameters, or returning anything, just passing code to be executed elsewhere.
Robert Mehew
2,427 PointsRobert Mehew
2,427 PointsNot sure if this will help.
When I was following a course on Swift on Treehouse I couldn't get the async_dispatch to work if I used () -> Void in, but it did work if I left it out and added a return at the end. It could be that xcode has updated to no longer require it, but i'm not 100%.