Observables

public enum Observables

Contains factory methods for creating common Observable instances for use with the Tealium SDK.

  • The block called when an Observable of Element emits an event.

    Declaration

    Swift

    typealias Observer<Element> = Observable<Element>.Observer
  • Creates a custom observable that can call Observer callbacks with values of type Element.

    Use this method to create different behaviors upon Observable subscription.

    Declaration

    Swift

    static func create<Element>(subscriptionHandler: @escaping Observable<Element>.SubscriptionHandler) -> Observable<Element>

    Parameters

    subscriptionHandler

    The code run every time the returned Observable is subscribed upon. Within this block you can call the Observer block with values of type Element.

    Return Value

    An Observable that can be subscribed upon. Every time someone subscribes to this Observable the subscriptionHandler will be invoked.

  • Returns an observable that will send only one event once the asyncFunction has completed.

    Declaration

    Swift

    static func callback<Element>(from asyncFunction: @escaping (@escaping Observer<Element>) -> Void) -> Observable<Element>

    Parameters

    asyncFunction

    is the function that needs to be called and needs to report the completion to the provided observer. This function will only be called when an observer subscribes to the returned Observable. Every subscription will cause the asyncFunction to be called again.

    Return Value

    a Observable that, when a new observer subscribes, will call the asyncFunction and publish a new event to the subscribers when the function completes.

  • Returns an observable that just reports the provided elements in order to each new subscriber.

    Declaration

    Swift

    static func just<Element>(_ elements: Element...) -> Observable<Element>
  • Returns an observable that just reports the provided elements in order to each new subscriber.

    Declaration

    Swift

    static func from<Element>(_ elements: [Element]) -> Observable<Element>
  • Returns an empty observable that never reports anything

    Declaration

    Swift

    static func empty<Element>() -> Observable<Element>
  • Returns a single observable with an array of Elements from the provided array of elements

    The first element published from the returned observable will be published when all the observables provided emit at list one element. All subsequent changes to any observable will be emitted one by one.

    Declaration

    Swift

    static func combineLatest<Element>(_ observables: [Observable<Element>]) -> Observable<[Element]>