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

后端 未结 8 2021
无人共我
无人共我 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:20

    AshKan answer is great but I came here looking for a missing method from the solution. Append:

    extension BehaviorRelay where Element: RangeReplaceableCollection {
            
        func append(_ subElement: Element.Element) {
            var newValue = value
            newValue.append(subElement)
            accept(newValue)
        }
    }
    

提交回复
热议问题