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

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

    How about this kind of extension:

    extension BehaviorRelay {
    
        var val: Element {
            get { value }
            set { accept(newValue) }
        }
    }
    

    Then use it as you were using the Variable, but instead of calling value, call val:

    myFilter.val.append(newModel)
    

提交回复
热议问题