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
action
A 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
value
Optional closure executed when a
value
event is observed.failed
Optional closure that accepts an
Error
parameter when a failed event is observed.completed
Optional closure executed when a
completed
event is observed.interruped
Optional closure executed when an
interrupted
event is observed. -
Puts an event into
self
.Declaration
Swift
public func send(_ event: Event)
-
Puts a
value
event intoself
.Declaration
Swift
public func send(value: Value)
Parameters
value
A value sent with the
value
event. -
Puts a failed event into
self
.Declaration
Swift
public func send(error: Error)
Parameters
error
An error object sent with failed event.
-
Puts a
completed
event intoself
.Declaration
Swift
public func sendCompleted()
-
Puts an
interrupted
event 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
value
events will be forwarded to the Observer. The binding will automatically terminate when the target is deinitialized, or when the source sends acompleted
event.Declaration
Swift
@discardableResult public static func <~ <Source: BindingSource> (observer: Signal<Value, Error>.Observer, source: Source) -> Disposable? where Source.Value == Value
Parameters
target
A target to be bond to.
source
A source to bind.
Return Value
A disposable that can be used to terminate binding before the deinitialization of the target or the source’s
completed
event.