Observing UIButton Tap with Combine?

Let me say that I have an IBOutlet object like

@IBOutlet weak var deleteButton: UIButton!

RxCocoa can make this button tap observable like

deleteButton.rx.tap

It doesn't look like Combine lets us observe a button tap. Am I right? I find one approach found at the following URL.

https://www.avanderlee.com/swift/custom-combine-publisher/

And Combine has no native approach? And you still have to use the IBAction?

Answered by OOPer in 690918022

It doesn't look like Combine lets us observe a button tap. Am I right?

Right.

Combine has no native approach? 

NO. At least, not yet.

you still have to use the IBAction?

Currently, target-action seems to be the only event handling scheme of UIKit. There may be some advances in the future, announced in WWDC 22 or later.


As you know, Combine seems to be mainly designed for SwiftUI and works well with SwiftUI.

If you want some native support for Combine in UIKit, you may want to write an enhancement request to Apple using the Feedback Assistant.

Accepted Answer

It doesn't look like Combine lets us observe a button tap. Am I right?

Right.

Combine has no native approach? 

NO. At least, not yet.

you still have to use the IBAction?

Currently, target-action seems to be the only event handling scheme of UIKit. There may be some advances in the future, announced in WWDC 22 or later.


As you know, Combine seems to be mainly designed for SwiftUI and works well with SwiftUI.

If you want some native support for Combine in UIKit, you may want to write an enhancement request to Apple using the Feedback Assistant.

Observing UIButton Tap with Combine?
 
 
Q