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

# iOS (Swift)

> Confidence iOS SDK for feature flag evaluation in Swift applications.

The Confidence iOS SDK provides feature flag evaluation for iOS, iPadOS, macOS, tvOS, and watchOS applications. Flags resolve once according to the evaluation context, and values read from a local cache for fast access.

## Features

* **Local caching**: Flag values cached locally for instant access
* **OpenFeature compatible**: Standard feature flag API through OpenFeature provider
* **Automatic apply events**: Tracks flag usage
* **Managed context**: Automatic visitor ID and app lifecycle context
* **Offline support**: Cached values available without network

## Installation

Add the package dependency to your `Package.swift`:

```swift theme={null}
dependencies: [
    .package(url: "git@github.com:spotify/confidence-sdk-swift.git", from: "<latest>")
]
```

Then add the products to your target:

```swift theme={null}
.product(name: "Confidence", package: "confidence-sdk-swift"),
.product(name: "ConfidenceOpenFeature", package: "confidence-sdk-swift"),
```

## Quickstart

The SDK uses OpenFeature for flag evaluation.

```swift theme={null}
import Confidence
import ConfidenceProvider
import OpenFeature

// Initialize Confidence
let confidence = Confidence.Builder(clientSecret: "your-client-secret", loggerLevel: .NONE)
    .build()

// Create OpenFeature provider with initial context
let provider = ConfidenceFeatureProvider(confidence: confidence)
let ctx = ImmutableContext(
    targetingKey: "user-123",
    structure: ImmutableStructure()
)

// Register with OpenFeature
await OpenFeatureAPI.shared.setProviderAndWait(provider: provider, initialContext: ctx)

// Get client and evaluate a flag
let client = OpenFeatureAPI.shared.getClient()
let value = client.getBooleanValue(key: "my-flag.my-boolean", defaultValue: false)
print("Flag value: \(value)")
```

## Resources

<CardGroup cols={2}>
  <Card title="GitHub repository" icon="github" href="https://github.com/spotify/confidence-sdk-swift">
    Source code, examples, and full documentation
  </Card>

  <Card title="OpenFeature iOS SDK" icon="flag" href="https://openfeature.dev/docs/reference/technologies/client/ios">
    OpenFeature documentation
  </Card>

  <Card title="Context" icon="sliders" href="/docs/sdks/context">
    Configure evaluation context
  </Card>

  <Card title="Apply events" icon="chart-line" href="/docs/sdks/apply-event">
    Understand flag assignment tracking
  </Card>
</CardGroup>
