gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 05:18:37 33 4
gpt4 key购买 nike

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

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com