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.

  • E

    The type of elements in sequence that observer can observe.

    Declaration

    Swift

    public typealias E = Element
  • 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<O>(_ observer: O) where Element == O.E, O : 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<E>

    Return Value

    type erased observer.