草庐IT

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

coder 2023-07-15 原文

使用 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

最佳答案

我们似乎不再在 Swift 4 中使用 Void in 了。我是如何修复它们的:

删除 Void 关键字:

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

你必须使用 in 或编译器 complain with

Expected ',' separator

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

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

关于 swift 4 : Cannot convert value of type '(_) -> ()' to expected argument type '() -> ()' or Argument passed to call that takes no arguments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45163720/

有关swift 4 : Cannot convert value of type '(_) -> ()' to expected argument type '() -> ()' or Argument passed to call that takes no arguments的更多相关文章

随机推荐