Swiftpack.co - Package - optimizely/swift-sdk
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.

SWIFT SDK

Apache 2.0 Carthage compatible Build Status Coverage Status Platforms Podspec

This repository houses the Swift SDK for use with Optimizely Full Stack and Optimizely Rollouts for Mobile and OTT.

Optimizely Full Stack is A/B testing and feature flag management for product development teams. Experiment in any application. Make every feature on your roadmap an opportunity to learn. Learn more at https://www.optimizely.com/platform/full-stack/, or see the documentation.

Optimizely Rollouts is free feature flags for development teams. Easily roll out and roll back features in any application without code deploys. Mitigate risk for every feature on your roadmap. Learn more at https://www.optimizely.com/rollouts/, or see the documentation.

Getting Started

Using the SDK

See the Mobile developer documentation to learn how to set up an Optimizely X project and start using the SDK.

Requirements

  • iOS 10.0+ / tvOS 10.0+
  • Swift 5+

Installing the SDK

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

Swift Package Manager

Add the following line to the dependencies value of your Package.swift:

dependencies: [
	.package(url: "https://github.com/optimizely/swift-sdk.git", 
    .upToNextMinor(from: “3.6.1”))
]

CocoaPods

  1. Add the following lines to the Podfile:
    use_frameworks!
    pod 'OptimizelySwiftSDK', '~> 3.6.1'
  1. Run the following command:
    pod install

Further installation instructions for Cocoapods: https://guides.cocoapods.org/using/getting-started.html

Carthage

  1. Add the following lines to the Cartfile:

    github "optimizely/swift-sdk" ~> 3.6.1

  2. Run the following command:

    carthage update

  3. Link the frameworks to your project. Go to your project target's Link Binary With Libraries and drag over the following from the Carthage/Build/<platform> folder:

    Optimizely.framework

  4. To ensure that proper bitcode-related files and dSYMs are copied when archiving your app, you will need to install a Carthage build script:

    • Add a new Run Script phase in your target's Build Phase.
    • In the script area include:
      /usr/local/bin/carthage copy-frameworks
    • Add the frameworks to the Input Files list:
      $(SRCROOT)/Carthage/Build/<platform>/Optimizely.framework
    • Add the paths to the copied frameworks to the Output Files list:
      $(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Optimizely.framework

Futher installation instructions for Carthage: https://github.com/Carthage/Carthage

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)
    }
}

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 repo:

For the SDK: 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.

Github

link
Stars: 8

Releases

Release 3.6.1 - 2020-11-19T21:07:36

3.6.1

November 19, 2020

New Features

  • Add "enabled" field to decision metadata structure. (#376)

Release 3.6.0 - 2020-11-04T23:00:34

3.6.0

November 4, 2020

New Features

  • Add support for upcoming application-controlled introduction of tracking for non-experiment Flag decisions. (#370)

Release 3.5.0 - 2020-10-02T22:31:15

3.5.0

October 2, 2020

New Features

  • Add versioning that follows semantic version types and tests. (#333)

Bug Fixes

  • Fixing log messages for Targeted Rollouts and feature variable evaluation. (#337)

Release 3.4.1 - 2020-09-23T01:09:52

3.4.1

September 22, 2020

Bug Fixes

  • Fix a bucketing error at traffic allocation boundaries. (#365)
  • Update DataStore directory on macOS. (#355)

Release 3.4.0 - 2020-07-09T22:51:16

3.4.0

July 9, 2020

New Features

  • Add support for JSON feature variables. (#315, #317, #318)
  • Add macOS Compatibility. (#332)

Bug Fixes

  • Add more audience evaluation logs. (#336)

Release 3.3.2 - 2020-05-22T19:50:27

3.3.2

May 21, 2020

Bug Fixes

  • Fix a decision bug for multi-rule rollouts (#323)
  • Fix to forward resourceTimeout to datafileHandler (#320)

Release 3.3.1 - 2020-03-31T00:28:58

3.3.1

March 30, 2020

Bug Fixes

  • When a datafile download for initialization returns connection errors, the SDK fails to initialize. This is fixed to continue initialization with a cached datafile. (#308)
  • Events are not stored persistently in the tvOS devices. (#310, #311)

Release 3.3.0 - 2020-03-11T22:00:22

3.3.0

March 11, 2020

This release includes an enhancement of SDK initialization API to enable SDK updated on cached datafile change. It also fixes known bugs.

New Features

  • Add an option for synchronous initialization to enable SDK immediately updated when a new datafile is cached. Unless this feature is enabled, by default, the cached datafile will be used only when the SDK re-starts in the next session. Note that this option is for synchronous initialization only. (#297)

     // enable SDK update when a new datafile is cached
     optimizelyClient.start(datafile: data, doUpdateConfigOnNewDatafile: true)
     
     // by default, this feature is disabled
     optimizelyClient.start(datafile: data)
    

Bug Fixes

  • When a synchronously-initialized SDK enables background datafile polling and its datafile was changed in the server, the new datafile is cached but SDK is not dynamically updated. (#297)
  • When background datafile polling is enabled and app goes to background and comes back to foreground after some delays, datafile fetching is called multiple times back-to-back. (#301)
  • NotificationCenter can cause crashes when multiple threads add/call listeners simultaneously. (#304)

Release 3.2.1 - 2020-01-16T18:00:03

3.2.1

January 16, 2020

Bug Fixes

  • Swift Package Manager (SPM) spec changed to iOS10+/tvOS10+

Release 3.2.0 - 2020-01-16T04:23:37

3.2.0

January 15, 2020

This release includes a new API to access project configuration data and other feature enhancements. It also fixes known bugs.

New Features

  • OptimizelyConfig (#274):
  • Add LogEvent Notification (#263):
    • Register an event listner with addLogEventNotificationListener().
    • The lister will be called when events are dispatched to the server.
  • Turn on "Allow app extensions only" flag in build settings (#277)

Bug Fixes

  • When timerInterval is set to a negative value, EventDispatcher is changed to use the default interval value for batching (instead of disabling batch). Batching is disabled when the timerInterval is set to zero. (#268)

Breaking Changes

  • Upgrade required platforms from iOS9+/tvOS9+ to iOS10+/tvOS10+ (#284)

Release 3.1.0 - 2019-08-01T16:20:50

3.1.0

July 31, 2019

This release is the GA launch of the Swift SDK. It is a pure Swift implementation which takes complete advantage of language features and performance. It supports Objective-C applications as well.

This modernized version of the SDK is meant to replace the Objective-C SDK.

New Features

In addition to all features and APIs support of the Objective-C SDK, this new SDK also adds the following new features:

  • By default the datafile handler does updates every 10 minutes when the application is in the foreground. To disable this, set the periodicUpdateInterval to zero. If you do allow for polling, the project will update automatically when a new datafile change is received.
  • On top of the above functionality, the developer may register for a datafile change notification. This notification will be called anytime a new datafile is downloaded to cache and is used to reinitialize the optimizely client automatically.
  • The event handler batches events and will run every minute in the foreground to send events. If there are no events in the queue it will not reschedule.

Bug Fixes

Breaking Changes

Release 3.1.0-beta - 2019-05-30T22:36:00

3.1.0-beta

May 30, 2019

This is the initial release of the Swift SDK. It is a pure Swift implementation which takes complete advantage of language features and performance. It supports Objective-C applications as well. It uses Swift 4.2 but we will be upgrading to 5.0 soon.

This modernized version of the SDK is meant to replace the Objective-C SDK.

New Features

  • By default the datafile handler does updates every 10 minutes when the application is in the foreground. To disable this, set the periodicUpdateInterval to zero. If you do allow for polling, the project will update automatically when a new datafile change is received.
  • On top of the above functionality, the developer may register for a datafile change notification. This notification will be called anytime a new datafile is downloaded to cache and is used to reinitialize the optimizely client automatically.
  • The event handler batches events and will run every minute in the foreground to send events. If there are no events in the queue it will not reschedule.

Bug Fixes:

Breaking Changes