Integration · SDK
Swift
The Swift client ships via Swift Package Manager as MetapolicySDK. iOS 15+, macOS 12+, watchOS 8+, tvOS 15+. Built around async/await and Swift Concurrency. No legacy completion-handler API surface.
The contract
What flows in
- Decide requests as async throws returning Assignment
- Reward events emitted through a single async call
- URLSession by default; supply your own if you have one configured
What flows out
- Assignment + propensity from the same call
- Errors as throws with typed cases for retry decisions
Setup
- 01Add Metapolicy package via Xcode → File → Add Package Dependencies
- 02Initialise once in your AppDelegate or App struct with the environment-scoped key
- 03Call await client.decide(...) at the decision site
- 04Emit rewards via await client.reward(...) when the outcome is observable
- 05SwiftUI: the @MetapolicyDecision property wrapper handles state + revalidation
iOS-side caching
Decisions are cached in an actor-isolated LRU keyed on (experiment, userId, contextHash). The cache is invalidated on scene-active transitions to ensure propensity reflects the live context after backgrounding.
Privacy: nothing is persisted to disk by default. The cache is process-memory only, so terminating the app clears all assignment state — matching the on-server source of truth.
Other sdk integrations
PythonAsync client for FastAPI / Django / Celery. Same six-method surface as every other SDK.TypeScriptUniversal client. Same wire format whether you ship in Node, the browser, or React Native.KotlinCoroutines-native client for Android + JVM backends. Same contract as every other SDK.FlutterDart 3 client for the Flutter mobile-growth stack. One client across iOS + Android.
Wire Swift in a 30-minute call.
We pair with your engineer, ship the integration live, and run the first decision on your stack.