BehaviorSubject
public final class BehaviorSubject<Element>
: Observable<Element>
, SubjectType
, ObserverType
, SynchronizedUnsubscribeType
, Cancelable
Represents a value that changes over time.
Observers can subscribe to the subject to receive the last (or initial) value and all subsequent notifications.
-
Undocumented
Declaration
Swift
public typealias SubjectObserverType = BehaviorSubject<Element>
-
Indicates whether the subject has any observers
Declaration
Swift
public var hasObservers: Bool { get }
-
Indicates whether the subject has been disposed.
Declaration
Swift
public var isDisposed: Bool { get }
-
Initializes a new instance of the subject that caches its last value and starts with the specified value.
Declaration
Swift
public init(value: Element)
Parameters
value
Initial value sent to observers when no other value has been received by the subject yet.
-
Gets the current value or throws an error.
Declaration
Swift
public func value() throws -> Element
Return Value
Latest value.
-
Notifies all subscribed observers about next event.
Declaration
Swift
public func on(_ event: Event<Element>)
Parameters
event
Event to send to the observers.
-
Subscribes an observer to the subject.
Declaration
Swift
public override func subscribe<Observer>(_ observer: Observer) -> Disposable where Element == Observer.Element, Observer : ObserverType
Parameters
observer
Observer to subscribe to the subject.
Return Value
Disposable object that can be used to unsubscribe the observer from the subject.
-
Returns observer interface for subject.
Declaration
Swift
public func asObserver() -> BehaviorSubject<Element>
-
Unsubscribe all observers and release resources.
Declaration
Swift
public func dispose()