【问题标题】:Compiler crashing when using variadic parameter in closure [duplicate]在闭包中使用可变参数时编译器崩溃[重复]
【发布时间】:2016-07-19 19:21:54
【问题描述】:

这是我在操场上尝试的代码:

let aVar: (Int...) -> () = {
    $0
}

编译器崩溃说The LLDB RPC server has crashed 并要求我向苹果报告错误。我什至试过这个:

let aVar: (Int...) -> () = { ints in
    ints //as soon as I write this, it crashes with the above message.
}

我只是想知道我所写的代码是否有效,因为我无法确认这一点,以及可变参数是否也可以作为参数提供给闭包。我正在使用Xcode 8 Beta 2。

【问题讨论】:

  • func aVar(numbers: Int...) -> () { for num in numbers { print("(num)") } } aVar(5,4,6,7)跨度>
  • 那是func @JoeyEtamity。我指的是closures。 @vacawama,目前没有解决 shorthand 参数的方法吗?

标签: ios swift swift3 xcode8


【解决方案1】:

来自Swift closure docs:

如果您命名可变参数,则可以使用可变参数

所以理论上这应该可行:

let aVar: (x: Int...) -> () = {
    print($0)
}

但编译器仍然崩溃,即使使用 Xcode 8,也可能是一个错误。我还不知道解决方法。

编辑:这个问题与How to use a variadic closure in swift? 重复。

【讨论】:

    猜你喜欢
    • 2015-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-31
    相关资源
    最近更新 更多