Driver

这是一个特殊设计的可被监听序列,主要用来对UI进行监听。 所以其具有某些鲜明的特色

  • 不会出现error
  • 一直在主线程执行(联系到UI更新必须在主线程执行)
  • Shares side effects (shareReplayLatestWhileConnected)

Driver
UI -> ?

  1. 无法外在改变其value
  2. 用于驱动UI、等其他一切都在主线程中运行的事物
  3. 可以驱动多个

一个特殊的序列 主要用于UI

public typealias Driver<E> = SharedSequence<DriverSharingStrategy, E>

        let drive = Observable.just(true).asDriver(onErrorJustReturn: false)
//        drive.drive(<#T##observer: ObserverType##ObserverType#>).dis...
//        drive.drive(<#T##observer: ObserverType##ObserverType#>).dis...
//        drive.drive(<#T##observer: ObserverType##ObserverType#>).dis...
  1. 每一次drive都需要处理这一个序列的生命周期。
  2. 这个生命周期是指什么东西的生命周期?

DriverSharingStrategy

public struct DriverSharingStrategy: SharingStrategyProtocol {
    public static var scheduler: SchedulerType { return SharingScheduler.make() }
    public static func share<E>(_ source: Observable<E>) -> Observable<E> {
        return source.share(replay: 1, scope: .whileConnected)
    }
}

results matching ""

    No results matching ""