Variable in action

The last of the subject types, and by no means the least, is variable. Remember that it's a wrapper around the BehaviorSubject that won't error out; it automatically completes and uses the dot "." syntax to get and set its values. 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 ReplaySubject:

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

We will create a variable by passing an initial value to its initializer. The type is inferred by the value passed, a variable of the Int type in this case:

let variable = Variable(1)

We will create a subscription to this variable and print out the emitted ...

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.