Swift 3转换 - 捕获列表中的功能

时间:2016-10-14 07:49:33

标签: swift3 capture

我正在尝试将项目从Swift 2.3转换为Swift 3。 转换器之前的代码是:

Swift 2.3中的代码

..., handler: { [performSegueWithIdentifier] _ in
    performSegueWithIdentifier("Help Segue", sender: nil)
}

转换器之后,在Swift 3.0中,代码变为:

..., handler: { [performSegue(withIdentifier:sender:)] _ in
    performSegueWithIdentifier("Help Segue", sender: nil)
}

但我有编译错误:

'Expected 'weak', 'unowned', or no specifier in capture list'

我尝试过:

  • 删除参数,但似乎是Expression type 'Void' (aka '()') is ambiguous without more context

1 个答案:

答案 0 :(得分:0)

错误: '表达式''Void'...'与第二行有关:

performSegue(withIdenfifier: "Help Segue", sender: nil)

所以,一切都会变成:

handler: { [performSegue] _ in
    performSegue("Help Segue", nil)
})