我将动作声明为
var postAction: Action<String, Data, NSError>!
现在我想要的是在按钮触发时触发此操作。
triggerBtn.reactive.pressed = CocoaAction(postAction)
但是不能。当使用反应性可可按下按钮时,如何触发某些操作?
我已经找到了一种观察动作的方法。
self.testBtn.reactive.trigger(for: .touchUpInside).observe{ event in
//do something
print(event)
}
,但不能弄清楚如何获取发件人并绑定自定义操作?
您的操作具有String
类型的输入,但默认可可攻入不输入(类型()
)。
取决于按下按钮时的输入应来自何处,您可以使用固定值(如果此时已知):
button.reactive.pressed = CocoaAction(postAction, input: "Some Input")
或InputTransFormer
button.reactive.pressed = CocoaAction(postAction) { sender in
// Calculate input for the action when the button is pressed
return "Some Value"
}