Skip to content
optimizelyPublic

Repository files navigation

Optimizely Swift SDK

Apache 2.0 Build Status Coverage Status

This repository houses the Swift SDK for use with Optimizely Feature Experimentation and Optimizely Full Stack (legacy) for Mobile and OTT.

Optimizely Feature Experimentation is an A/B testing and feature management tool for product development teams, enabling you to experiment at every step. Using Optimizely Feature Experimentation allows for every feature on your roadmap to be an opportunity to discover hidden insights. Learn more at Optimizely.com, or see the developer documentation.

Optimizely Rollouts is free feature flags for development teams. You can easily roll out and roll back features in any application without code deploys, mitigating risk for every feature on your roadmap.

Get started

Use the Swift SDK

Refer to the Swift SDK's developer documentation for detailed instructions on getting started with using the SDK.

Requirements

  • iOS 15.0+ / tvOS 15.0+ / watchOS 9.0+ / macOS 12.0+
  • Swift 5+

Install the SDK

Please note below that <platform> is used to represent the platform on which you are building your app. Currently, we support iOS, tvOS, and watchOS platforms.

Swift Package Manager

Add the dependency on the Optimizely Swift SDK with Swift Package Manager in Xcode.

  1. File -> Swift Packages -> Add Package Dependency
  2. Enter https://github.com/optimizely/swift-sdk.
  3. Accept the default rules (Version: 'Up to Next Major').

If you have a name conflict with other swift packages when you add the Optimizely swift-sdk dependency to Xcode, you can also try with its aliased repo: "https://github.com/optimizely/optimizely-swift-sdk.git".

Migration note

CocoaPods support has been removed as part of the SDK's move to Swift Package Manager ahead of the ecosystem's end-of-2026 support sunset.

  • Use Swift Package Manager for all new and existing integrations.
  • The module name remains Optimizely, so existing import Optimizely statements do not change.

Feature Management Access

To access the Feature Management configuration in the Optimizely dashboard, please contact your Optimizely customer success manager.

Use the Swift SDK

Samples

A sample code for SDK initialization and experiments:

let optimizely = OptimizelyClient(sdkKey:"somesdkkey")

optimizely.start{ result in
    do {
        let variation = try optimizely.activate(experimentKey: "background_experiment", userId: "userId", attributes: ["doubleKey":5])
        try optimizely.track(eventKey: "sample_conversion", userId: "userId")
    } catch {
        print(error)
    }
}

See the Optimizely Feature Experimentation developer documentation to learn how to set up your first Swift project and use the SDK.

Contributing

Please see CONTRIBUTING.

Credits

First-party code (under OptimizelySwiftSDK is copyright Optimizely, Inc. and contributors, licensed under Apache 2.0.)

Additional Code

This software incorporates code from the following open source projects:

MurmurHash3:https://github.com/jpedrosa/sua/blob/master/Sources/murmurhash3.swift License (Apache 2.0):https://github.com/jpedrosa/sua/blob/master/LICENSE.txt Ported to Swift4.

SwiftLint:https://github.com/realm/SwiftLint License (MIT):https://github.com/realm/SwiftLint/blob/master/LICENSE Used to enforce Swift style and conventions.

Other Optimizely SDKs

Releases

Packages

Used by

Contributors

Languages