Swift 4:无法将类型'(_) - >()'的值转换为预期的参数类型'() - >()'或传递给不带参数的调用的参数

Esq*_*uth 15 closures swift swift4

使用XCode 9,Beta 3. Swift 4.

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

我得到了这样的数百个错误,如何修复它们?

错误:

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

Argument passed to call that takes no arguments
Run Code Online (Sandbox Code Playgroud)

Zey*_*maz 32

我们似乎不再使用Void inSwift 4了.我是如何修理它们的:

删除Void关键字:

statsView.createButton("Button name") { [weak self] in
   //stuff stuff
   self?.doSomething()
}
Run Code Online (Sandbox Code Playgroud)

你必须使用in或编译器与抱怨

Expected ',' separator
Run Code Online (Sandbox Code Playgroud)

如果没有参数,则根本不使用Void in.

statsView.createButton("Button name") { //No "Void in" in here
   print("hi")
}
Run Code Online (Sandbox Code Playgroud)