Closure tuple does not support destructuring in Xcode 9 Swift 4

前端 未结 4 434
情深已故
情深已故 2020-12-17 07:48

After the gloss project for Swift 4 in Xcode 9

I am getting following error which i have no idea

Closure tuple parameter \'(key: _, value: _)

4条回答
  •  天涯浪人
    2020-12-17 08:37

    I just encountered this error as a result of using enumerated().map():

    Closure tuple parameter does not support destructuring

    I typed the code:

    ["foo"].enumerated().map
    

    And then pressed Enter 3 times until Xcode autocompleted the closure boilerplate.

    The autocomplete seemingly has a bug that causes the above error. The autocomplete produces double-parenthesis ((offset: Int, element: String)) rather than single-parenthesis (offset: Int, element: String).

    I fixed it manually and was able to continue:

    // Xcode autocomplete suggests:
    let fail = ["foo"].enumerated().map { ((offset: Int, element: String)) -> String in
        return "ERROR: Closure tuple parameter does not support destructuring"
    }
    
    // Works if you manually replace the "(( _ ))" with "( _ )"
    let pass = ["foo"].enumerated().map { (offset: Int, element: String) -> String in
        return "works"
    }
    

    Possibly the result of using Xcode 10.0 beta (10L176w)

提交回复
热议问题