Engineering

Try Signal in RxSwift 4.0

Signal

Signal has introduced in RxSwift4.0.
I've tried to watch differences Driver and Signal.

https://github.com/ReactiveX/RxSwift/pull/1116

Try

Code

import RxSwift
import RxCocoa

let source = PublishSubject<Int>()

let d = source.asDriver(onErrorRecover: { _ in .empty() })
let s = source.asSignal(onErrorRecover: { _ in .empty() })

source.onNext(1)

d.debug("First Drive").drive()
s.debug("First Emit ").emit()

source.onNext(2)

d.debug("Second Drive").drive()
s.debug("Second Emit ").emit()

Result

First Drive -> subscribed
First Emit  -> subscribed
First Drive -> Event next(2)
First Emit  -> Event next(2)
Second Drive -> subscribed
Second Drive -> Event next(2)
Second Emit  -> subscribed

Conclusion

  • Driver share events.
  • Signal doesn't share events.

Definitely, It just emits events.