11.3 · PassthroughSubject, CurrentValueSubject and @Published

Subjects are publishers you can push values into by hand: the bridge from imperative code into a pipeline. @Published is the same idea built into a property.

Mental model. A subject is a mailbox you can post to. Passthrough is a mailbox with no memory; current-value is a noticeboard that always shows the latest notice.

Pushing values in

The two subjects and the property wrapper that wraps one.

  1. What is the difference between PassthroughSubject and CurrentValueSubject, and when do you use a subject at all? 11.3.1 · L2
    A subject is both a publisher and something you can send values and completions into. PassthroughSubject<Output, Failure> has no state: it forwards values to…
  2. How does @Published work, and why does a subscriber see the old value inside its sink? 11.3.2 · L3
    @Published is a property wrapper that stores the value and exposes a publisher through the projected value: $name is a Published<T>.Publisher (never fails).…

More in Combine