> ## Documentation Index
> Fetch the complete documentation index at: https://launchdarkly.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Set up iOS SDK

> Install and initialize the LaunchDarkly iOS SDK to start evaluating feature flags in your application.

**Developer**

**Federal docs**

**EU docs**

**Federal docs**

> [!CAUTION]
>
> **LaunchDarkly onboarding is not available in federal environments**
>
> To learn more, read [LaunchDarkly in federal environments](https://launchdarkly.com/docs/home/infrastructure/federal).

Install and initialize the LaunchDarkly iOS SDK to start evaluating feature flags in your application.

## Install the package

```swift title="Swift" lines wrap theme={null}
//...
    dependencies: [
        .package(url: "https://github.com/launchdarkly/ios-client-sdk.git", .upToNextMajor(from: "11.5.0")),
   ],
    targets: [
        .target(
            name: "YOUR_TARGET",
            dependencies: ["LaunchDarkly"]
        )
    ],
//...
```

```ruby title="Podfile" lines wrap theme={null}
use_frameworks!
target 'YourTargetName' do
  pod 'LaunchDarkly', '~> 11.5'
end
```

```swift title="Cartfile" lines wrap theme={null}
github "launchdarkly/ios-client-sdk" ~> 11.5
```

### Initialize the SDK for feature management

```swift title="iOS SDK initialization" expandable lines wrap theme={null}
import LaunchDarkly

// This is your mobile key.
let config = LDConfig(mobileKey: "YOUR_MOBILE_KEY", autoEnvAttributes: .enabled)

// A "context" is a data object representing users, devices, organizations, and other entities.
let contextBuilder = LDContextBuilder(key: "EXAMPLE_CONTEXT_KEY")
guard case .success(let context) = contextBuilder.build()
else { return }

LDClient.start(config: config, context: context, startWaitSeconds: 5) { timedOut in
    if timedOut {
        print("SDK didn't initialize in 5 seconds.  SDK is still running and trying to get latest flags.")
    } else {
        print("SDK successfully initialized with the latest flags")
    }
}

print("SDK started.")
```

### Initialize the SDK for feature management and Experimentation

If you want to use the LaunchDarkly [Experimentation](https://launchdarkly.com/docs/home/experimentation) feature, include a track call in your initialization code:

```swift title="iOS SDK initialization for Experimentation" expandable lines wrap theme={null}
import LaunchDarkly

// Call this once from your app startup (e.g. application(_:didFinishLaunchingWithOptions:)).
// You can't invoke LDClient.start() at the top level in Swift — wrap it in a function.
func startLaunchDarkly() {
    // This is your mobile key.
    let config = LDConfig(mobileKey: "YOUR_MOBILE_KEY", autoEnvAttributes: .enabled)

    // A "context" is a data object representing users, devices, organizations, and other entities.
    var contextBuilder = LDContextBuilder(key: "EXAMPLE_CONTEXT_KEY")
    contextBuilder.trySetValue("email", .string("EXAMPLE_EMAIL"))
    guard case .success(let context) = contextBuilder.build() else { return }

    LDClient.start(config: config, context: context, startWaitSeconds: 5) { timedOut in
        if timedOut {
            print("SDK didn't initialize in 5 seconds. SDK is still running and trying to get latest flags.")
        } else {
            print("SDK successfully initialized with the latest flags")
        }
    }
}

// Call trackMetric when a metric action occurs in your app —
// a tap, a form submit, a screen view, a custom event, whatever your metric measures.
func trackMetric(metricKey: String, data: LDValue = .null) {
    let client = LDClient.get()!
    client.track(key: metricKey, data: data)
}
```

> [accordion] Finding your SDK credentials
>
> You can find your server-side SDK keys, mobile keys, and client-side ID on the **SDK keys** page under **Settings**.

To learn more, read [Initialize the client](https://launchdarkly.com/docs/sdk/client-side/ios#initialize-the-client) in the iOS SDK reference guide.
