[英]Converting my application to new Swift - error “Extra argument in call”
I recently converted my watch app to Swift 4 and I received the following error: "Extra argument 'var2' in call". 最近,我将手表应用程序转换为Swift 4,并收到以下错误消息:“调用中的额外参数'var2'”。 The code is in a Singleton with an array/dictionary, here is the reference code:
该代码在具有数组/字典的Singleton中,以下是参考代码:
class foo {
static let sharedInstance = foo()
var currentFlag: Bool = true
var a:[(var1: Int, var2:Int, var3:Bool)] = []
private init() {
}
func test(v1:Int, v2:Int) {
a.append(var1: v1, var2: v2, var3: Bool(currentFlag)) // <-- error here
}
}
Check this proposal for Swift 4: SE-0110 Distinguish between single-tuple and multiple-argument function types 请查看有关Swift 4的建议: SE-0110区分单元组和多参数函数类型
Some implementation details have changed in betas, but in your case, you need to append another pair of parentheses: Beta中的一些实现详细信息已更改,但是在您的情况下,您需要添加另一对括号:
func test(v1:Int, v2:Int) {
a.append((var1: v1, var2: v2, var3: Bool(currentFlag)))
}
By the way, you declare your currentFlag
as Bool
, so Bool(currentFlag)
is sort of redundant: 顺便说一句,您将
currentFlag
声明为Bool
,所以Bool(currentFlag)
有点多余:
func test(v1:Int, v2:Int) {
a.append((var1: v1, var2: v2, var3: currentFlag))
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.