LDMultiContextBuilder

public struct LDMultiContextBuilder

Contains method for building a multi-context.

Use this type if you need to construct a LDContext that has multiple kind values, each with its own nested LDContext. To define a single-kind context, use LDContextBuilder instead.

Obtain an instance of LDMultiContextBuilder by calling LDMultiContextBuilder.init(); then, call LDMultiContextBuilder.addContext(_:) to specify the nested LDContext for each kind. LDMultiContextBuilder setters return a reference the same builder, so they can be chained together.

  • Create a new LDMultiContextBuilder with the provided key.

    Declaration

    Swift

    public init()
  • Adds a nested context for a specific kind to a LDMultiContextBuilder.

    It is invalid to add more than one context with the same Kind. This error is detected when you call LDMultiContextBuilder.build().

    Adding a multi-kind context behaves the same as if each single-kind context was added individually.

    Declaration

    Swift

    public mutating func addContext(_ context: LDContext)
  • Creates a LDContext from the current properties.

    The LDContext is immutable and will not be affected by any subsequent actions on the LDMultiContextBuilder.

    It is possible for a LDMultiContextBuilder to represent an invalid state. In those situations, a Result.failure will be returned.

    If only one context kind was added to the builder, build returns a single-kind context rather than a multi-context.

    Declaration

    Swift

    public func build() -> Result<LDContext, ContextBuilderError>