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

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

    On Variable used to have:

    let variable = Variable("Hello RxSwift")
    variable.value = "Change text" 
    print(variable.value) // "Change text"
    

    On BehaviorRelay you have to use:

    let relay = BehaviorRelay(value: "Hello RxSwift")
    relay.accept("Change text")
    print(relay.value) // "Change text"
    

提交回复
热议问题