LDClient

public class LDClient

The LDClient is the heart of the SDK, providing client apps running iOS, watchOS, macOS, or tvOS access to LaunchDarkly services. This singleton provides the ability to set a configuration (LDConfig) that controls how the LDClient talks to LaunchDarkly servers, and a user (LDUser) that provides finer control on the feature flag values delivered to LDClient. Once the LDClient has started, it connects to LaunchDarkly’s servers to get the feature flag values you set in the Dashboard.

Usage

Startup

  1. To customize, configure a LDConfig and LDUser. The config is required, the user is optional. Both give you additional control over the feature flags delivered to the LDClient. See LDConfig & LDUser for more details.
    • The mobileKey set into the LDConfig comes from your LaunchDarkly Account settings. If you have multiple projects be sure to choose the correct Mobile key.
  2. Call LDClient.start(config: user: completion:)
    • If you do not pass in a LDUser, LDClient will create a default for you.
    • The optional completion closure allows the LDClient to notify your app when it received flag values.
  3. Because LDClient instances are stored statically, you do not have to keep a reference to it in your code. Get the primary instances with LDClient.get()

Getting Feature Flags

Once the LDClient has started, it makes your feature flags available using the variation and variationDetail methods. A variation is a specific flag value. For example a boolean feature flag has 2 variations, true and false. You can create feature flags with more than 2 variations using other feature flag types.

 let boolFlag = LDClient.get()?.variation(forKey: "my-bool-flag", defaultValue: false)

If you need to know more information about why a given value is returned, use variationDetail.

See variation(forKey: defaultValue:) or variationDetail(forKey: defaultValue:) for details

Observing Feature Flags

You might need to know when a feature flag value changes. This is not required, you can check the flag’s value when you need it.

If you want to know when a feature flag value changes, you can check the flag’s value. You can also use one of several observe methods to have the LDClient notify you when a change occurs. There are several options–you can set up notificiations based on when a specific flag changes, when any flag in a collection changes, or when a flag doesn’t change.

 LDClient.get()?.observe("flag-key", owner: self, observer: { [weak self] (changedFlag) in
    self?.updateFlag(key: "flag-key", changedFlag: changedFlag)
 }

The changedFlag passed in to the closure contains the old and new value of the flag.

State Controls and Indicators

  • Reports the online/offline state of the LDClient.

    When online, the SDK communicates with LaunchDarkly servers for feature flag values and event reporting.

    When offline, the SDK does not attempt to communicate with LaunchDarkly servers. Client apps can request feature flag values and set/change feature flag observers while offline. The SDK will collect events while offline.

    Use setOnline(_: completion:) to change the online/offline state.

    Declaration

    Swift

    public private(set) var isOnline: Bool { get set }
  • Reports the initialization state of the LDClient.

    When true, the SDK has either communicated with LaunchDarkly servers for feature flag values or the SDK has been set offline.

    When false, the SDK has not been able to communicate with LaunchDarkly servers. Client apps can request feature flag values and set/change feature flag observers but flags might not exist or be stale.

    Declaration

    Swift

    public var isInitialized: Bool { get }
  • Set the LDClient online/offline.

    When online, the SDK communicates with LaunchDarkly servers for feature flag values and event reporting.

    When offline, the SDK does not attempt to communicate with LaunchDarkly servers. Client apps can request feature flag values and set/change feature flag observers while offline. The SDK will collect events while offline.

    The SDK protects itself from multiple rapid calls to setOnline(true) by enforcing an increasing delay (called throttling) each time setOnline(true) is called within a short time. The first time, the call proceeds normally. For each subsequent call the delay is enforced, and if waiting, increased to a maximum delay. When the delay has elapsed, the setOnline(true) will proceed, assuming that the client app has not called setOnline(false) during the delay. Therefore a call to setOnline(true) may not immediately result in the LDClient going online. Client app developers should consider this situation abnormal, and take steps to prevent the client app from making multiple rapid setOnline(true) calls. Calls to setOnline(false) are not throttled. Note that calls to start(config: user: completion:), and setting the config or user can also call setOnline(true) under certain conditions. After the delay, the SDK resets and the client app can make a susequent call to setOnline(true) without being throttled.

    Client apps can set a completion closure called when the setOnline call completes. For unthrottled setOnline(true) and all setOnline(false) calls, the SDK will call the closure immediately on completion of this method. For throttled setOnline(true) calls, the SDK will call the closure after the throttling delay at the completion of the setOnline method.

    The SDK will not go online if the client has not been started, or the mobileKey is empty. For macOS, the SDK will not go online in the background unless enableBackgroundUpdates is true.

    Use isOnline to get the online/offline state.

    Declaration

    Swift

    public func setOnline(_ goOnline: Bool, completion: (() -> Void)? = nil)

    Parameters

    goOnline

    Desired online/offline mode for the LDClient

    completion

    Completion closure called when setOnline completes (Optional)

  • Returns an object containing information about successful and/or failed polling or streaming connections to LaunchDarkly

    Declaration

    Swift

    public func getConnectionInformation() -> ConnectionInformation
  • Stops the LDClient. Stopping the client means the LDClient goes offline and stops recording events. LDClient will no longer provide feature flag values, only returning default values.

    There is almost no reason to stop the LDClient. Normally, set the LDClient offline to stop communication with the LaunchDarkly servers. Stop the LDClient to stop recording events. There is no need to stop the LDClient prior to suspending, moving to the background, or terminating the app. The SDK will respond to these events as the system requires and as configured in LDConfig.

    Declaration

    Swift

    public func close()
  • The LDUser set into the LDClient may affect the set of feature flags returned by the LaunchDarkly server, and ties event tracking to the user. See LDUser for details about what information can be retained.

    Normally, the client app should create and set the LDUser and pass that into start(config: user: completion:).

    The client app can change the active user by calling identify with a new or updated LDUser. Client apps should follow Apple’s Privacy Policy when collecting user information. If the client app does not create a LDUser, LDClient creates an anonymous default user, which can affect the feature flags delivered to the LDClient.

    When a new user is set, the LDClient goes offline and sets the new user. If the client was online when the new user was set, it goes online again, subject to a throttling delay if in force (see setOnline(_: completion:) for details). To change both the config and user, set the LDClient offline, set both properties, then set the LDClient online. A completion may be passed to the identify method to allow a client app to know when fresh flag values for the new user are ready.

    Declaration

    Swift

    public func identify(user: LDUser, completion: (() -> Void)? = nil)

    Parameters

    user

    The LDUser set with the desired user.

    completion

    Closure called when the embedded setOnlineIdentify call completes, subject to throttling delays. (Optional)

Retrieving Flag Values

  • Returns the variation for the given feature flag. If the flag does not exist, cannot be cast to the correct return type, or the LDClient is not started, returns the default value. Use this method when the default value is a non-Optional type. See variation with the Optional return value when the default value can be nil.

    A variation is a specific flag value. For example a boolean feature flag has 2 variations, true and false. You can create feature flags with more than 2 variations using other feature flag types. See LDFlagValue for the available types.

    The LDClient must be started in order to return feature flag values. If the LDClient is not started, it will always return the default value. The LDClient must be online to keep the feature flag values up-to-date.

    When online, the LDClient has two modes for maintaining feature flag values: streaming and polling. The client app requests the mode by setting the config.streamingMode, see LDConfig for details.

    • In streaming mode, the LDClient opens a long-running connection to LaunchDarkly’s streaming server (called clientstream). When a flag value changes on the server, the clientstream notifies the SDK to update the value. Streaming mode is not available on watchOS. On iOS and tvOS, the client app must be running in the foreground to connect to clientstream. On macOS the client app may run in either foreground or background to connect to clientstream. If streaming mode is not available, the SDK reverts to polling mode.
    • In polling mode, the LDClient requests feature flags from LaunchDarkly’s app server at regular intervals defined in the LDConfig. When a flag value changes on the server, the LDClient will learn of the change the next time the SDK requests feature flags.

    When offline, LDClient closes the clientstream connection and no longer requests feature flags. The LDClient will return feature flag values (assuming the LDClient was started), which may not match the values set on the LaunchDarkly server.

    A call to variation records events reported later. Recorded events allow clients to analyze usage and assist in debugging issues.

    Usage

    let boolFeatureFlagValue = LDClient.get()!.variation(forKey: "bool-flag-key", defaultValue: false) //boolFeatureFlagValue is a Bool
    

    Important The default value tells the SDK the type of the feature flag. In several cases, the feature flag type cannot be determined by the values sent from the server. It is possible to provide a default value with a type that does not match the feature flag value’s type. The SDK will attempt to convert the feature flag’s value into the type of the default value in the variation request. If that cast fails, the SDK will not be able to determine the correct return type, and will always return the default value.

    Pay close attention to the type of the default value for collections. If the default value collection type is more restrictive than the feature flag, the sdk will return the default value even though the feature flag is present because it cannot convert the feature flag into the type requested via the default value. For example, if the feature flag has the type [String: Any], but the default value has the type [String: Int], the sdk will not be able to convert the flags into the requested type, and will return the default value.

    To avoid this, make sure the default value type matches the expected feature flag type. Either specify the default value type to be the feature flag type, or cast the default value to the feature flag type prior to making the variation request. In the above example, either specify that the default value’s type is [String: Any]:

    let defaultValue: [String: Any] = ["a": 1, "b": 2]     //dictionary type would be [String: Int] without the type specifier
    

    or cast the default value into the feature flag type prior to calling variation:

    let dictionaryFlagValue = LDClient.get()!.variation(forKey: "dictionary-key", defaultValue: ["a": 1, "b": 2] as [String: Any])
    

    Declaration

    Swift

    public func variation<T>(forKey flagKey: LDFlagKey, defaultValue: T) -> T where T : LDFlagValueConvertible

    Parameters

    forKey

    The LDFlagKey for the requested feature flag.

    defaultValue

    The default value to return if the feature flag key does not exist.

    Return Value

    The requested feature flag value, or the default value if the flag is missing or cannot be cast to the default value type, or the client is not started

  • Returns the LDEvaluationDetail for the given feature flag. LDEvaluationDetail gives you more insight into why your variation contains the specified value. If the flag does not exist, cannot be cast to the correct return type, or the LDClient is not started, returns an LDEvaluationDetail with the default value. Use this method when the default value is a non-Optional type. See variationDetail with the Optional return value when the default value can be nil. See variationWithdefaultValue

    Declaration

    Swift

    public func variationDetail<T>(forKey flagKey: LDFlagKey, defaultValue: T) -> LDEvaluationDetail<T> where T : LDFlagValueConvertible

    Parameters

    forKey

    The LDFlagKey for the requested feature flag.

    defaultValue

    The default value value to return if the feature flag key does not exist.

    Return Value

    LDEvaluationDetail which wraps the requested feature flag value, or the default value, which variation was served, and the evaluation reason.

  • Returns the variation for the given feature flag. If the flag does not exist, cannot be cast to the correct return type, or the LDClient is not started, returns the default value, which may be nil. Use this method when the default value is an Optional type. See variation with the non-Optional return value when the default value cannot be nil.

    A variation is a specific flag value. For example a boolean feature flag has 2 variations, true and false. You can create feature flags with more than 2 variations using other feature flag types. See LDFlagValue for the available types.

    The LDClient must be started in order to return feature flag values. If the LDClient is not started, it will always return the default value. The LDClient must be online to keep the feature flag values up-to-date.

    When online, the LDClient has two modes for maintaining feature flag values: streaming and polling. The client app requests the mode by setting the config.streamingMode, see LDConfig for details.

    • In streaming mode, the LDClient opens a long-running connection to LaunchDarkly’s streaming server (called clientstream). When a flag value changes on the server, the clientstream notifies the SDK to update the value. Streaming mode is not available on watchOS. On iOS and tvOS, the client app must be running in the foreground to connect to clientstream. On macOS the client app may run in either foreground or background to connect to clientstream. If streaming mode is not available, the SDK reverts to polling mode.
    • In polling mode, the LDClient requests feature flags from LaunchDarkly’s app server at regular intervals defined in the LDConfig. When a flag value changes on the server, the LDClient will learn of the change the next time the SDK requests feature flags.

    When offline, LDClient closes the clientstream connection and no longer requests feature flags. The LDClient will return feature flag values (assuming the LDClient was started), which may not match the values set on the LaunchDarkly server.

    A call to variation records events reported later. Recorded events allow clients to analyze usage and assist in debugging issues.

    Usage

    let boolFeatureFlagValue: Bool? = LDClient.get()!.variation(forKey: "bool-flag-key", defaultValue: nil) //boolFeatureFlagValue is a Bool?
    

    Important The default value tells the SDK the type of the feature flag. In several cases, the feature flag type cannot be determined by the values sent from the server. It is possible to provide a default value with a type that does not match the feature flag value’s type. The SDK will attempt to convert the feature flag’s value into the type of the default value in the variation request. If that cast fails, the SDK will not be able to determine the correct return type, and will always return the default value.

    When specifying nil as the default value, the compiler must also know the type of the optional. Without this information, the compiler will give the error “‘nil’ requires a contextual type”. There are several ways to provide this information, by setting the type on the item holding the return value, by casting the return value to the desired type, or by casting nil to the desired type. We recommend following the above example and setting the type on the return value item.

    For this method, the default value is defaulted to nil, allowing the call site to omit the default value.

    Pay close attention to the type of the default value for collections. If the default value collection type is more restrictive than the feature flag, the sdk will return the default value even though the feature flag is present because it cannot convert the feature flag into the type requested via the default value. For example, if the feature flag has the type [String: Any], but the default value has the type [String: Int], the sdk will not be able to convert the flags into the requested type, and will return the default value.

    To avoid this, make sure the default value type matches the expected feature flag type. Either specify the default value value type to be the feature flag type, or cast the default value value to the feature flag type prior to making the variation request. In the above example, either specify that the default value’s type is [String: Any]:

    let defaultValue: [String: Any]? = ["a": 1, "b": 2]     //dictionary type would be [String: Int] without the type specifier
    

    or cast the default value into the feature flag type prior to calling variation:

    let dictionaryFlagValue = LDClient.get()!.variation(forKey: "dictionary-key", defaultValue: ["a": 1, "b": 2] as [String: Any]?)
    

    Declaration

    Swift

    public func variation<T>(forKey flagKey: LDFlagKey, defaultValue: T? = nil) -> T? where T : LDFlagValueConvertible

    Parameters

    forKey

    The LDFlagKey for the requested feature flag.

    defaultValue

    The default value to return if the feature flag key does not exist. If omitted, the default value is nil. (Optional)

    Return Value

    The requested feature flag value, or the default value if the flag is missing or cannot be cast to the default value type, or the client is not started

  • Returns the LDEvaluationDetail for the given feature flag. LDEvaluationDetail gives you more insight into why your variation contains the specified value. If the flag does not exist, cannot be cast to the correct return type, or the LDClient is not started, returns an LDEvaluationDetail with the default value, which may be nil. Use this method when the default value is a Optional type. See variationWithoutdefaultValue

    Declaration

    Swift

    public func variationDetail<T>(forKey flagKey: LDFlagKey, defaultValue: T? = nil) -> LDEvaluationDetail<T?> where T : LDFlagValueConvertible

    Parameters

    forKey

    The LDFlagKey for the requested feature flag.

    defaultValue

    The default value to return if the feature flag key does not exist. If omitted, the default value is nil. (Optional)

    Return Value

    LDEvaluationDetail which wraps the requested feature flag value, or the default value, which variation was served, and the evaluation reason.

  • Returns a dictionary with the flag keys and their values. If the LDClient is not started, returns nil.

    The dictionary will not contain feature flags from the server with null values.

    LDClient will not provide any source or change information, only flag keys and flag values. The client app should convert the feature flag value into the desired type.

    Declaration

    Swift

    public var allFlags: [LDFlagKey : Any]? { get }

Observing Updates

  • Sets a handler for the specified flag key executed on the specified owner. If the flag’s value changes, executes the handler, passing in the changedFlag containing the old and new flag values. See LDChangedFlag for details.

    The SDK retains only weak references to the owner, which allows the client app to freely destroy observer owners without issues. Client apps should use a capture list specifying [weak self] inside handlers to avoid retain cycles causing a memory leak.

    The SDK executes handlers on the main thread.

    LDChangedFlag does not know the type of oldValue or newValue. The client app should cast the value into the type needed. See variation(forKey: defaultValue:) for details about the SDK and feature flag types.

    SeeAlso: LDChangedFlag and stopObserving(owner:)

    Usage

    LDClient.get()?.observe("flag-key", owner: self) { [weak self] (changedFlag) in
       if let newValue = changedFlag.newValue as? Bool {
           //do something with the newValue
       }
    

    Declaration

    Swift

    public func observe(key: LDFlagKey, owner: LDObserverOwner, handler: @escaping LDFlagChangeHandler)

    Parameters

    key

    The LDFlagKey for the flag to observe.

    owner

    The LDObserverOwner which will execute the handler. The SDK retains a weak reference to the owner.

    handler

    The closure the SDK will execute when the feature flag changes.

  • Sets a handler for the specified flag keys executed on the specified owner. If any observed flag’s value changes, executes the handler 1 time, passing in a dictionary of [LDFlagKey: LDChangedFlag] containing the old and new flag values. See LDChangedFlag for details.

    The SDK retains only weak references to owner, which allows the client app to freely destroy observer owners without issues. Client apps should use a capture list specifying [weak self] inside handlers to avoid retain cycles causing a memory leak.

    The SDK executes handlers on the main thread.

    LDChangedFlag does not know the type of oldValue or newValue. The client app should cast the value into the type needed. See variation(forKey: defaultValue:) for details about the SDK and feature flag types.

    SeeAlso: LDChangedFlag and stopObserving(owner:)

    Usage

    LDClient.get()?.observe(flagKeys, owner: self) { [weak self] (changedFlags) in     // changedFlags is a [LDFlagKey: LDChangedFlag]
       //There will be an LDChangedFlag entry in changedFlags for each changed flag. The closure will only be called once regardless of how many flags changed.
       if let someChangedFlag = changedFlags["some-flag-key"] {    // someChangedFlag is a LDChangedFlag
           //do something with someChangedFlag
        }
    }
    

    Declaration

    Swift

    public func observe(keys: [LDFlagKey], owner: LDObserverOwner, handler: @escaping LDFlagCollectionChangeHandler)

    Parameters

    keys

    An array of LDFlagKeys for the flags to observe.

    owner

    The LDObserverOwner which will execute the handler. The SDK retains a weak reference to the owner.

    handler

    The LDFlagCollectionChangeHandler the SDK will execute 1 time when any of the observed feature flags change.

  • Sets a handler for all flag keys executed on the specified owner. If any flag’s value changes, executes the handler 1 time, passing in a dictionary of [LDFlagKey: LDChangedFlag] containing the old and new flag values. See LDChangedFlag for details.

    The SDK retains only weak references to owner, which allows the client app to freely destroy observer owners without issues. Client apps should use a capture list specifying [weak self] inside handlers to avoid retain cycles causing a memory leak.

    The SDK executes handlers on the main thread.

    LDChangedFlag does not know the type of oldValue or newValue. The client app should cast the value into the type needed. See variation(forKey: defaultValue:) for details about the SDK and feature flag types.

    SeeAlso: LDChangedFlag and stopObserving(owner:)

    Usage

    LDClient.get()?.observeAll(owner: self) { [weak self] (changedFlags) in     // changedFlags is a [LDFlagKey: LDChangedFlag]
       //There will be an LDChangedFlag entry in changedFlags for each changed flag. The closure will only be called once regardless of how many flags changed.
       if let someChangedFlag = changedFlags["some-flag-key"] {    // someChangedFlag is a LDChangedFlag
           //do something with someChangedFlag
       }
    }
    

    Declaration

    Swift

    public func observeAll(owner: LDObserverOwner, handler: @escaping LDFlagCollectionChangeHandler)

    Parameters

    owner

    The LDObserverOwner which will execute the handler. The SDK retains a weak reference to the owner.

    handler

    The LDFlagCollectionChangeHandler the SDK will execute 1 time when any of the observed feature flags change.

  • Sets a handler executed when a flag update leaves the flags unchanged from their previous values.

    This handler can only ever be called when the LDClient is polling.

    The SDK retains only weak references to owner, which allows the client app to freely destroy observer owners without issues. Client apps should use a capture list specifying [weak self] inside handlers to avoid retain cycles causing a memory leak.

    The SDK executes handlers on the main thread.

    SeeAlso: stopObserving(owner:)

    Usage

    LDClient.get()?.observeFlagsUnchanged(owner: self) { [weak self] in
        // Do something after an update was received that did not update any flag values.
        //The closure will be called once on the main thread after the update.
    }
    

    Declaration

    Swift

    public func observeFlagsUnchanged(owner: LDObserverOwner, handler: @escaping LDFlagsUnchangedHandler)

    Parameters

    owner

    The LDObserverOwner which will execute the handler. The SDK retains a weak reference to the owner.

    handler

    The LDFlagsUnchangedHandler the SDK will execute 1 time when a flag request completes with no flags changed.

  • Sets a handler executed when ConnectionInformation.currentConnectionMode changes.

    The SDK retains only weak references to owner, which allows the client app to freely destroy change owners without issues. Client apps should use a capture list specifying [weak self] inside handlers to avoid retain cycles causing a memory leak.

    The SDK executes handlers on the main thread.

    SeeAlso: stopObserving(owner:)

    Usage

    LDClient.get()?.observeCurrentConnectionMode(owner: self) { [weak self] in
       //do something after ConnectionMode was updated.
    }
    

    Declaration

    Swift

    public func observeCurrentConnectionMode(owner: LDObserverOwner, handler: @escaping LDConnectionModeChangedHandler)

    Parameters

    owner

    The LDObserverOwner which will execute the handler. The SDK retains a weak reference to the owner.

    handler

    The LDConnectionModeChangedHandler the SDK will execute 1 time when ConnectionInformation.currentConnectionMode is changed.

  • Removes all observers for the given owner, including the flagsUnchangedObserver

    The client app does not have to call this method. If the client app deinits a LDFlagChangeOwner, the SDK will automatically remove its handlers without ever calling them again.

    Declaration

    Swift

    public func stopObserving(owner: LDObserverOwner)

    Parameters

    owner

    The LDFlagChangeOwner owning the handlers to remove, whether a flag change handler or flags unchanged handler.

  • Undocumented

    Declaration

    Swift

    public func observeError(owner: LDObserverOwner, handler: @escaping LDErrorHandler)

Events

  • Adds a custom event to the LDClient event store. A client app can set a tracking event to allow client customized data analysis. Once an app has called track, the app cannot remove the event from the event store.

    LDClient periodically transmits events to LaunchDarkly based on the frequency set in LDConfig.eventFlushInterval. The LDClient must be started and online. Ths SDK stores events tracked while the LDClient is offline, but started.

    Once the SDK’s event store is full, the SDK discards events until they can be reported to LaunchDarkly. Configure the size of the event store using eventCapacity on the config. See LDConfig for details.

    Usage

    let appEventData = ["some-custom-key: "some-custom-value", "another-custom-key": 7]
    LDClient.get()?.track(key: "app-event-key", data: appEventData)
    

    Throws

    LDInvalidArgumentError if the data is not a valid JSON item

    Declaration

    Swift

    public func track(key: String, data: Any? = nil, metricValue: Double? = nil) throws

    Parameters

    key

    The key for the event. The SDK does nothing with the key, which can be any string the client app sends

    data

    The data for the event. The SDK does nothing with the data, which can be any valid JSON item the client app sends. (Optional)

    metricValue

    A numeric value used by the LaunchDarkly experimentation feature in numeric custom metrics. Can be omitted if this event is used by only non-numeric metrics. This field will also be returned as part of the custom event for Data Export. (Optional)

  • Tells the SDK to generate an alias event.

    Associates two users for analytics purposes.

    This can be helpful in the situation where a person is represented by multiple LaunchDarkly users. This may happen, for example, when a person initially logs into an application– the person might be represented by an anonymous user prior to logging in and a different user after logging in, as denoted by a different user key.

    Declaration

    Swift

    public func alias(context new: LDUser, previousContext old: LDUser)

    Parameters

    context

    the user that will be aliased to

    previousContext

    the user that will be bound to the new context

  • Tells the SDK to immediately send any currently queued events to LaunchDarkly.

    There should not normally be a need to call this function. While online, the LDClient automatically reports events on an interval defined by LDConfig.eventFlushInterval. Note that this function does not block until events are sent, it only triggers a background task to send events immediately.

    Declaration

    Swift

    public func flush()

Initializing and Accessing

  • Starts the LDClient using the passed in config & user. Call this before requesting feature flag values. The LDClient will not go online until you call this method. Starting the LDClient means setting the config & user, setting the client online if config.startOnline is true (the default setting), and starting event recording. The client app must start the LDClient before it will report feature flag values. If a client does not call start, no methods will work. If the start call omits the user, the LDClient uses a default LDUser. If thestart call includes the optional completion closure, LDClient calls the completion closure when setOnline(_: completion:) embedded in the init method completes. This method listens for flag updates so the completion will only return once an update has occurred. The start call is subject to throttling delays, therefore the completion closure call may be delayed. Subsequent calls to this method cause the LDClient to return. Normally there should only be one call to start. To change user, use identify.

    Declaration

    Swift

    public static func start(config: LDConfig, user: LDUser? = nil, completion: (() -> Void)? = nil)

    Parameters

    configuration

    The LDConfig that contains the desired configuration. (Required)

    user

    The LDUser set with the desired user. If omitted, LDClient sets a default user. (Optional)

    completion

    Closure called when the embedded setOnline call completes. (Optional)

  • See start for more information on starting the SDK.

    Declaration

    Swift

    public static func start(config: LDConfig, user: LDUser? = nil, startWaitSeconds: TimeInterval, completion: ((_ timedOut: Bool) -> Void)? = nil)

    Parameters

    configuration

    The LDConfig that contains the desired configuration. (Required)

    user

    The LDUser set with the desired user. If omitted, LDClient sets a default user. (Optional)

    startWaitSeconds

    A TimeInterval that determines when the completion will return if no flags have been returned from the network.

    completion

    Closure called when the embedded setOnline call completes. Takes a Bool that indicates whether the completion timedout as a parameter. (Optional)

  • Returns the LDClient instance for a given environment.

    Declaration

    Swift

    public static func get(environment: String = LDConfig.Constants.primaryEnvironmentName) -> LDClient?

    Parameters

    environment

    The name of an environment provided in LDConfig.secondaryMobileKeys, defaults to LDConfig.Constants.primaryEnvironmentName which is always associated with the LDConfig.mobileKey environment.

    Return Value

    The requested LDClient instance.