Variable
public final class Variable<Element>
Variable is a wrapper for BehaviorSubject
.
Unlike BehaviorSubject
it can’t terminate with error, and when variable is deallocated
it will complete its observable sequence (asObservable
).
This concept will be deprecated from RxSwift but offical migration path hasn’t been decided yet. https://github.com/ReactiveX/RxSwift/issues/1501
Current recommended replacement for this API is RxCocoa.BehaviorRelay
because:
Variable
isn’t a standard cross platform concept, hence it’s out of place in RxSwift target.- It doesn’t have a counterpart for handling events (
PublishRelay
). It models state only. - It doesn’t have a consistent naming with *Relay or other Rx concepts.
- It has an inconsistent memory management model compared to other parts of RxSwift (completes on
deinit
).
Once plans are finalized, official availability attribute will be added in one of upcoming versions.
-
Undocumented
Declaration
Swift
public typealias E = Element
-
Gets or sets current value of variable.
Whenever a new value is set, all the observers are notified of the change.
Even if the newly set value is same as the old value, observers are still notified for change.
Declaration
Swift
public var value: E { get set }
-
Initializes variable with initial value.
Declaration
Swift
public init(_ value: Element)
Parameters
value
Initial variable value.
-
Declaration
Swift
public func asObservable() -> Observable<E>
Return Value
Canonical interface for push style sequence