How to use BehaviorRelay as an alternate to Variable in RxSwift?

后端 未结 8 1893
无人共我
无人共我 2021-01-30 03:52

As of RxSwift4, Variable is moved to Deprecated.swift marking the possible deprecation of Variable in future. An alternate proposed to

8条回答
  •  故里飘歌
    2021-01-30 04:32

    I would do something like that -

    let requests = PublishSubject>.create()
    let responses: Observable = requests.switchLatest()
    
    let parsed: Observable<[ParsedItem]> = responses
      .flatMap { Observable.from($0).map { parse($0) }.toArray() }
    
    parsed.bind(to: ui)
    
    // repeated part
    let request1: Observable = servive.call()
    request.onNext(request1)
    

提交回复
热议问题