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

问题描述:

使用XCode 9,Beta 3。Swift 4:无法将类型'(_) - >()'的值转换为期望的参数类型'() - >()'或传递给不带参数的调用的参数

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

我得到了数百个这样的错误,我该如何解决它们?

错误:

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

Argument passed to call that takes no arguments 

看来我们不斯威夫特4使用Void in了。我该如何修复这些问题:

删除Void关键字:

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

你必须使用in或编译器与

Expected ',' separator 

抱怨如果没有参数那么就不要使用Void in在所有。

statsView.createButton("Button name") { //No "Void in" in here 
    print("hi") 
}