Observer
public final class Observer
An Observer is a simple wrapper around a function which can receive Events (typically from a Signal).
-
An initializer that accepts a closure accepting an event for the observer.
Declaration
Swift
public init(_ action: @escaping Action )Parameters
actionA closure to lift over received event.
-
An initializer that accepts closures for different event types.
Declaration
Swift
public convenience init( value: ((Value) -> Void)? = nil, failed: ((Error) -> Void)? = nil, completed: (() -> Void)? = nil, interrupted: (() -> Void)? = nil )Parameters
valueOptional closure executed when a
valueevent is observed.failedOptional closure that accepts an
Errorparameter when a failed event is observed.completedOptional closure executed when a
completedevent is observed.interrupedOptional closure executed when an
interruptedevent is observed. -
Puts an event into
self.Declaration
Swift
public func send(_ event: Event ) -
Puts a
valueevent intoself.Declaration
Swift
public func send(value: Value)Parameters
valueA value sent with the
valueevent. -
Puts a failed event into
self.Declaration
Swift
public func send(error: Error)Parameters
errorAn error object sent with failed event.
-
Puts a
completedevent intoself.Declaration
Swift
public func sendCompleted() -
Puts an
interruptedevent intoself.Declaration
Swift
public func sendInterrupted() -
Binds a source to a target, updating the target’s value to the latest value sent by the source.
Note
Only
valueevents will be forwarded to the Observer. The binding will automatically terminate when the target is deinitialized, or when the source sends acompletedevent.Declaration
Swift
@discardableResult public static func <~ <Source: BindingSource > (observer: Signal <Value, Error>.Observer, source: Source) -> Disposable ? where Source.Value == ValueParameters
targetA target to be bond to.
sourceA source to bind.
Return Value
A disposable that can be used to terminate binding before the deinitialization of the target or the source’s
completedevent.