简体   繁体   中英

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". The code is in a Singleton with an array/dictionary, here is the reference code:

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

Some implementation details have changed in betas, but in your case, you need to append another pair of parentheses:

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:

func test(v1:Int, v2:Int) {
    a.append((var1: v1, var2: v2, var3: currentFlag))
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM