ReplaySubject in action

ReplaySubject will maintain and replay a buffer of the size you specify of the latest next events in the order they were emitted. To create a ReplaySubject, you need to explicitly declare a type because the initializer does not take an initial value, so it can't infer the type and use the create(bufferSize:) static convenience method to pass the number of elements you want replayed to new subscribers for the bufferSize parameter. Similar to the last section, we will start this section with a basic code setup and build on top of the previous example by just commenting out the sample code for BehaviorSubject:

executeProcedure(for: "ReplaySubject"){    let disposeBag = DisposeBag()}

Then, to this basic implementation we ...

Get Reactive Programming with Swift 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.