Skip to main content
TrevoSDK runs experiments and records events in iOS apps, assigning the same variant the web SDK does for the same user. Swift, no dependencies, iOS 15 and later (also visionOS and macOS). On tvOS it works, but tvOS only lets an app keep files in a cache it may clear, so a device can lose its anonymous id. In Xcode, choose File → Add Package Dependencies and enter https://github.com/trevosdk/trevosdk-ios. In a Package.swift:

Create the client

Use a Mobile key (tsk_live_…). Keep it in your build configuration, for example an xcconfig value exposed in Info.plist, and create one client for the app’s lifetime:
The client reads the build’s version from CFBundleShortVersionString, so minAppVersion gating and the version on every event work with no setup.

Read a variant

getVariant is synchronous and safe on the main thread. It returns control until stored state and the first config fetch have loaded, so wait for ready() before showing experiment UI, the way you would wait for a signed-in user:
Each call records an exposure the first time. Pass trackExposure: false to read without recording one. onChange calls a listener on the main thread whenever config or identity changes; keep the returned TrevoSubscription and cancel() it when the view goes away.

Parameters

A parameter lets later experiments change a value with no release:
There are overloads for String, Bool, Int and Double. A value of another type, or a number that isn’t whole for an Int, serves the default. A String parameter can carry text per language: pass your app’s own translation as the default, and if users can pick the app’s language, call trevo.setLocale("pt-BR") when they do. Without it the SDK reads the localization the app runs in.

Track events and identify users

Events are queued on disk and sent in batches every 15 seconds, when the app moves to the background, and on await trevo.flush(). See Mobile experiments for how experiments ramp on mobile, how the SDK survives a lost network, and the App Store and Google Play answers. The package ships its own privacy manifest.

Options

Correctness

The package runs the shared conformance vectors in CI, so a change that would assign a user differently from the web fails the build. The rules are in the bucketing spec.