无法将类型 'Void'(又名“()”)的值分配给类型“() -> Void”

Cannot assign value of type 'Void' (aka '()') to type '() -> Void'

有一个 UIView 的 class 实例,其作用类似于按钮。 它有 属性:

public var endPressAction:(()->Void)?

还有一个控制器的方法:

func didPressCell(_ indexPath: IndexPath){

我正在尝试将控制器的方法作为参数传递给 "button",如下所示:

button.endPressAction = self.didPressCell(indexPath)

但我收到错误消息:

Cannot assign value of type 'Void' (aka '()') to type '() -> Void'

有谁知道转换的方法吗?

我找到了一种转换方式:

button.endPressAction = { self.didPressCell(indexPath) }