Concept

UI Binding in Combine connects user input to a reactive pipeline, and updates the UI based on emitted values.

It enables a continuous data flow:

UI input → Combine pipeline → UI output

This creates a reactive loop where UI changes automatically reflect processed data.


Key Idea

UIKit is not reactive by default.

To use Combine, we introduce a bridge:

UITextField → Subject → Combine pipeline → UILabel

A Subject is used to convert UI events into a stream.


Using a Subject

let textSubject = PassthroughSubject<String, Never>()

This subject:

receives values manually
emits values to subscribers
does not store previous values

Capturing UI Input

UIKit uses target-action:

textField.addTarget(self, action: #selector(textDidChange), for: .editingChanged)