我有一个带有以下参数的 CustomAlertView:
public var title: String
public var buttonText: String
public var buttonAction: (() -> ())?
...通过以下方式调用专用函数:
Button(action: {buttonAction() })
我可以使用以下代码运行代码和任何功能
customAlert = CustomAlertView(title: "Item found",
buttonText: "Take it",
buttonAction: closePopup
)
showCustomAlert = true
...
func closePopup() { showCustomAlert = false }
我想添加一些带参数的函数,例如
closePopupAndGetItemWithID(1)
但我不能打电话给他们,它说:
无法将“()”类型的值转换为预期的参数类型“(() -> ())?”
我如何需要在我的 CustomAlertView 中转换 var 以允许有和没有参数的函数?
谁能解释一下这是什么意思:(()->())?