RxCocoa 의 Traits 중 하나

질문: Driver 란? (대답해보기)

핵심

생성방법

구현코드

public func asDriver(onErrorJustReturn: Element) -> Driver<Element> {
        let source = self
            .asObservable()
            .observeOn(DriverSharingStrategy.scheduler)
            .catchErrorJustReturn(onErrorJustReturn)
        return Driver(source)
}

깨달은 점

???

var disposeBag = DisposeBag()

var sequence = Observable<Int>.interval(.seconds(1), scheduler: MainScheduler.instance)
    .take(5)
    .asDriver(onErrorJustReturn: 0)

sequence.drive(onNext: {
    print($0)
}).disposed(by: disposeBag)