0

I'm trying to do something that I thought was simple: Dismiss my view and do a delegate call in the completion.

This compiles fine:

dismissViewControllerAnimated(true, completion:nil)
self.delegate?.accountCreated(self.account)

So does this:

dismissViewControllerAnimated(true, completion: { () -> Void in
    let tester = Account()
})

self.delegate?.accountCreated(self.account)

However, this is giving an error:

dismissViewControllerAnimated(true, completion: { () -> Void in
    self.delegate?.accountCreated(self.account)
})

Error on the dismissViewControllerAnimated call: Cannot convert the expression's type '(BooleanLiteralConvertible,completion:() -> Void)' to type 'Void'

I don't understand why I'm getting this error. (Xcode 6.1b2)

Aaron Bratcher
  • 6,051
  • 2
  • 39
  • 70
  • Swift is trying to implicitly return the Bool that your method returns through the closure. You can get around this if you move spread your code out onto 2 lines. e.g. `let tmp = self.account` and `self.delegate?.accountCreated(tmp)`. – Mick MacCallum Sep 16 '14 at 20:09
  • Changing it to 2 lines did the trick. Very strange. – Aaron Bratcher Sep 16 '14 at 20:15

0 Answers0