For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Sign inTry it free
DocsGuidesSDKsIntegrationsAPI docsTutorialsFlagship blog
DocsGuidesSDKsIntegrationsAPI docsTutorialsFlagship blog
  • Get started
    • Overview
    • Onboarding
      • Set up .NET (server-side) SDK
      • Set up Android SDK
      • Set up Go SDK
      • Set up iOS SDK
      • Set up Java SDK (server-side)
      • Set up JavaScript SDK
      • Set up Node.js (client-side) SDK
      • Set up Node.js (server-side) SDK
      • Set up Python SDK
      • Set up React Native SDK
      • Set up React Web SDK
      • Set up Vue SDK
    • Get started
    • Launch Insights
    • LaunchDarkly architecture
    • LaunchDarkly vocabulary
  • AgentControl
    • AgentControl
    • Manage AgentControl
  • Feature flags
    • Create flags
    • Target with flags
    • Flag templates
    • Manage flags
    • Code references
    • Contexts
    • Segments
  • Releases
    • Releasing features with LaunchDarkly
    • Release policies
    • Percentage rollouts
    • Progressive rollouts
    • Guarded rollouts
    • Feature monitoring
    • Release pipelines
    • Engineering insights
    • Release management tools
    • Applications and app versions
    • Change history
    • Restoring previous flag versions
  • Observability
    • Observability
    • Session replay
    • Error monitoring
    • Logs
    • Traces
    • Observability metrics
    • Product analytics events
    • LLM observability
    • Alerts
    • Dashboards
    • Service map
    • Vega for auto-remediation
    • Observability MCP server
    • Search specification
    • Observability settings
    • Observability integrations
  • Experimentation
    • Experimentation
    • Experiment metric types
    • Experiment configuration
    • Managing experiments
    • Analyzing experiments
    • Multi-armed bandits
    • Holdouts
  • Metrics and events
    • Metrics in LaunchDarkly
    • Creating metrics
    • Metric groups
    • Events
    • Autogenerated metrics
  • Warehouse native
    • Warehouse native metrics
    • Setting up external warehouses
    • Creating experiments using warehouse native metrics
  • Infrastructure
    • Connect apps and services to LaunchDarkly
    • LaunchDarkly in China and Pakistan
    • LaunchDarkly in the European Union (EU)
    • LaunchDarkly in federal environments
    • Public IP list
  • Your account
    • Projects
    • Views
    • Environments
    • Tags
    • Teams
    • Members
    • Roles
    • Account security
    • Feature previews
    • Billing and usage
    • Changelog
Sign inTry it free
LogoLogo
On this page
  • Install the package
  • Initialize the SDK
Get startedOnboarding

Set up iOS SDK

Was this page helpful?
Previous

Set up Java SDK

Next
Built with
Read docsAutomate in Cursor

Install the package

1//...
2 dependencies: [
3 .package(url: "https://github.com/launchdarkly/ios-client-sdk.git", .upToNextMajor(from: "9.15.0")),
4 ],
5 targets: [
6 .target(
7 name: "YOUR_TARGET",
8 dependencies: ["LaunchDarkly"]
9 )
10 ],
11//...

Initialize the SDK

iOS SDK initialization
1import LaunchDarkly
2
3// This is your mobile key.
4let config = LDConfig(mobileKey: "YOUR_MOBILE_KEY", autoEnvAttributes: .enabled)
5
6// A "context" is a data object representing users, devices, organizations, and other entities.
7let contextBuilder = LDContextBuilder(key: "EXAMPLE_CONTEXT_KEY")
8guard case .success(let context) = contextBuilder.build()
9else { return }
10
11LDClient.start(config: config, context: context, startWaitSeconds: 5) { timedOut in
12 if timedOut {
13 print("SDK didn't initialize in 5 seconds. SDK is still running and trying to get latest flags.")
14 } else {
15 print("SDK successfully initialized with the latest flags")
16 }
17}
18
19print("SDK started.")
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 in the iOS SDK reference guide.