Other Classes

The following classes are available globally.

  • Wraps a hook so that repeated evaluations resolving to the same result do not reach it again within a time window.

    The wrapped hook is told about a flag when its result changes, and at most once per window while the result stays the same. This is useful for reducing the telemetry volume produced by frequent re-evaluations, for example a flag that is read on every redraw of a view. Deduplication is opt-in: a hook that is registered unwrapped observes every evaluation.

    This class is not stable, and not subject to any backwards compatibility guarantees or semantic versioning. It is experimental.

    config.hooks = [
        MetricsHook(),                                     // observes every evaluation
        DedupingHook(ObservabilityHook()),                  // default window
        DedupingHook(TelemetryHook(), window: 60),
        DedupingHook(ExperimentHook(), deduper: sharedDeduper)
    ]
    

    Two evaluations resolve to the same result when they agree on everything EvaluationExposureKey describes.

    An evaluation the SDK has no flag data for resolves to the default value, and is the same result as another that does. Evaluations made before the client has flags are of that kind, so the wrapped hook is told about one of them and then told about the flag again as soon as its data arrives.

    A suppressed evaluation reaches neither beforeEvaluation nor afterEvaluation, because hooks pair their stages. The identify and track stages are always forwarded. Analytics events are unaffected: feature, debug, and summary events are still recorded for every evaluation, so the evaluation counts LaunchDarkly reports for your flags do not change.

    What the wrapped hook has been told about is cleared by LDClient.identify(context:), so the first evaluation of each flag after an identify always reaches it.

    Give each hook its own instance unless you intend hooks to share a window: the first hook to be told about an evaluation starts the window that suppresses the rest.

    Wrap outermost when you stack hooks that wrap other hooks. Suppressing an evaluation means returning series data that says so in place of what the stage was given, so a wrapper outside this one does not get back what it stored in its own before stage. A wrapper inside this one is unaffected, since a suppressed evaluation never reaches it.

    See more

    Declaration

    Swift

    public final class DedupingHook : HookDecorator
  • Decides whether a hook should be told about an evaluation, so that repeated evaluations resolving to the same result do not invoke the hook again within a time window.

    This class is not stable, and not subject to any backwards compatibility guarantees or semantic versioning. It is experimental. Subclassing it to change which evaluations are deduplicated is supported, but the shape it is subclassed through, and the components of EvaluationExposureKey a subclass reasons about, may change.

    Deduplication is opt-in per hook: a hook is told about every evaluation until you wrap it in a DedupingHook, which is what consults a deduper.

    config.hooks = [
        MetricsHook(),                                     // told about every evaluation
        DedupingHook(ObservabilityHook()),                  // default window
        DedupingHook(TelemetryHook(), window: 30),
        DedupingHook(ExperimentHook(), deduper: sharedDeduper)
    ]
    

    This class is the SDK’s implementation: it remembers the result each flag last reported, and tells the hook about the flag again as soon as that result changes, or once the window elapses while it stays the same. Tracking one result per flag rather than every result seen keeps a flag that flips back and forth from hiding the flips, and holds one record per flag the application evaluates, so the window is the only thing there is to configure.

    A deduper is consulted once per evaluation, before the series opens, so a suppressed evaluation invokes neither beforeEvaluation nor afterEvaluation. Implementations must be thread-safe, because evaluations may be made from any thread. Give each hook its own instance unless you intend hooks to share a window: the first hook to be told about an exposure starts the window that suppresses the rest.

    See more

    Declaration

    Swift

    open class EvaluationExposureDeduper
  • Contextual information that will be provided to handlers during evaluation series.

    See more

    Declaration

    Swift

    public class EvaluationSeriesContext
  • A hook that wraps another hook, forwarding every stage to it. A subclass adds behavior to a hook without changing it, and is registered in place of the hook it wraps.

    Every stage forwards to the wrapped hook, so a subclass overrides only the stages it changes, and calls super to forward the ones it does. The stages it leaves alone still reach the wrapped hook.

    An override that never calls super stops forwarding that stage. For the identify and track stages that means a decorator swallows something it has no reason to: a DedupingHook inside such an override is never told to forget what it has reported, and goes on suppressing evaluations across an identify.

    class FlagFilteringHook: HookDecorator {
        private let flagKeys: Set<LDFlagKey>
    
        init(_ delegate: Hook, flagKeys: Set<LDFlagKey>) {
            self.flagKeys = flagKeys
            super.init(delegate)
        }
    
        override func beforeEvaluation(seriesContext: EvaluationSeriesContext,
                                       seriesData: EvaluationSeriesData) -> EvaluationSeriesData {
            guard flagKeys.contains(seriesContext.flagKey)
            else { return seriesData }
            return super.beforeEvaluation(seriesContext: seriesContext, seriesData: seriesData)
        }
    }
    

    That hook filters evaluations and still forwards identify and track, which it never mentions.

    DedupingHook is the decorator the SDK ships: it forwards an evaluation series only when the flag’s result is one its hook has not just been told about.

    Decorators stack, so a hook may be wrapped in as many as it needs, each wrapping the one inside it:

    config.hooks = [DedupingHook(FlagFilteringHook(ObservabilityHook(), flagKeys: myFlagKeys))]
    

    A decorator reports the wrapped hook’s metadata as its own, so the SDK names the hook that a stage belongs to rather than the wrappers around it.

    A decorator that suppresses a stage must suppress the whole evaluation series, because hooks pair their stages: an observability hook opens a span in beforeEvaluation and closes it in afterEvaluation, so suppressing only the after stage leaves that span open. To carry the decision from one stage to the other, return series data the after stage recognizes, the way DedupingHook does.

    A decorator that does that belongs outermost, because the series data it returns replaces what it was given: a decorator outside it does not get back what it stored in its own before stage.

    This class is not stable, and not subject to any backwards compatibility guarantees or semantic versioning. It is experimental.

    See more

    Declaration

    Swift

    open class HookDecorator : Hook
  • Contextual information that will be provided to handlers during identify series.

    See more

    Declaration

    Swift

    public class IdentifySeriesContext
  • Metadata data class used for annotating hook implementations.

    See more

    Declaration

    Swift

    public class Metadata
  • Contextual information that will be provided to handlers during track series.

    See more

    Declaration

    Swift

    public class TrackSeriesContext
  • Metadata about the environment that flag evaluations or other functionalities are being performed in.

    This class provides context information to plugins about the environment they are running in, including application information, SDK metadata, and authentication credentials.

    See more

    Declaration

    Swift

    public class EnvironmentMetadata
  • Metadata used for annotating plugin implementations.

    This class provides identifying information about a plugin, primarily used for logging and debugging purposes.

    See more

    Declaration

    Swift

    public class PluginMetadata
  • Metadata about the LaunchDarkly SDK.

    This class provides information about the SDK version and name for informational purposes such as logging and debugging.

    See more

    Declaration

    Swift

    public class SdkMetadata
  • Use LDApplicationInfo to define application metadata.

    These properties are optional and informational. They may be used in LaunchDarkly analytics or other product features.

    See more

    Declaration

    Swift

    @objc(LDApplicationInfo)
    public final class ObjcLDApplicationInfo : NSObject
  • Contains methods for building a single kind LDContext with a specified key, defaulting to kind “user”.

    You may use these methods to set additional attributes and/or change the kind before calling LDContextBuilder.build(). If you do not change any values, the defaults for the LDContext are that its kind is “user”, its key is set to whatever value you passed to LDContextBuilder.init(key:), its anonymous attribute is false, and it has no values for any other attributes.

    To define a multi-context, see LDMultiContextBuilder.

    See more

    Declaration

    Swift

    @objc(LDContextBuilder)
    public final class ObjcLDContextBuilder : NSObject
  • 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.

    See more

    Declaration

    Swift

    @objc(LDMultiContextBuilder)
    public final class ObjcLDMultiContextBuilder : NSObject
  • An NSObject which mimics Swift’s Result type, specifically for the LDContext type.

    See more

    Declaration

    Swift

    @objc
    public class ContextBuilderResult : NSObject
  • Undocumented

    See more

    Declaration

    Swift

    @objc(ReferenceError)
    public final class ObjcLDReferenceError : NSObject