Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift 4: Cannot convert value of type '(_) -> ()' to expected argument type '() -> ()' or Argument passed to call that takes no arguments

Using XCode 9, Beta 3. Swift 4.

statsView.createButton("Button name") { [weak self] Void in
   //stuff stuff
   self?.doSomething()
}

I get hundreds of errors like this, how do I fix them?

Errors:

Cannot convert value of type '(_) -> ()' to expected argument type '() -> ()'

Argument passed to call that takes no arguments
like image 931
Esqarrouth Avatar asked Jul 18 '17 10:07

Esqarrouth


1 Answers

It seems we don't use Void in in Swift 4 anymore. How I fixed them:

Delete the Void keyword:

statsView.createButton("Button name") { [weak self] in
   //stuff stuff
   self?.doSomething()
}

You have to use in or the compiler with complain with

Expected ',' separator

If there is no arguments then don't use Void in at all.

statsView.createButton("Button name") { //No "Void in" in here
   print("hi")
}
like image 182
Zeynep Akkalyoncu Avatar answered Sep 29 '22 10:09

Zeynep Akkalyoncu