I answered something like this a couple of days ago for a related issue re: Swift's 'implicit return value for single-expression closure': animateWithDuration:animations:completion: in Swift
In this case, the method popViewControllerAnimated
returns the UIViewController that was popped from the stack: (https://developer.apple.com/library/ios/documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html#//apple_ref/occ/instm/UINavigationController/popViewControllerAnimated:)
Even though you aren't explicitly doing anything with the return value of that method, Swift is using that value (the returned UIViewController) as the return value for the closure - however, the closure is expecting a return value of Void.
When you added the extra parens ()
, you essentially added another line to the closure, and since it is no longer a 'single-expression closure' it no longer implicit returns the popped UIViewController.
The community will eventually settle on a convention for handling this, for now when I have been running into it I have been advocating adding return ()
to the end of the closure (as it clearly states the intention, (1) short circuiting the 'implicit return' by adding another statement, and (2) explicitly returning what was expected).