AnyObserver

public struct AnyObserver<Element> : ObserverType

A type-erased ObserverType.

Forwards operations to an arbitrary underlying observer with the same Element type, hiding the specifics of the underlying observer type.

  • Anonymous event handler type.

    Declaration

    Swift

    public typealias EventHandler = (Event<Element>) -> Void
  • Construct an instance whose on(event) calls eventHandler(event)

    Declaration

    Swift

    public init(eventHandler: @escaping EventHandler)

    Parameters

    eventHandler

    Event handler that observes sequences events.

  • Construct an instance whose on(event) calls observer.on(event)

    Declaration

    Swift

    public init<Observer>(_ observer: Observer) where Element == Observer.Element, Observer : ObserverType

    Parameters

    observer

    Observer that receives sequence events.

  • Send event to this observer.

    Declaration

    Swift

    public func on(_ event: Event<Element>)

    Parameters

    event

    Event instance.

  • Erases type of observer and returns canonical observer.

    Declaration

    Swift

    public func asObserver() -> AnyObserver<Element>

    Return Value

    type erased observer.