Server-side A/B testing and feature flags for iOS and macOS apps. Talks to the Mida API at https://api.mida.so.
- Swift 5.7+
- iOS 13+ / macOS 10.15+
- Uses Swift concurrency (
async/await)
In Xcode: File → Add Package Dependencies… and add this repository by URL, or add a local package by selecting the folder that contains Package.swift.
Alternatively, in your Package.swift, depend on the package by local path or by Git URL once this repo is published:
dependencies: [
.package(path: "./path/to/ios-sdk") // directory that contains Package.swift
]Then add the Mida product to your target.
import Mida
let mida = Mida(projectKey: "YOUR_PROJECT_KEY")
// A/B test variant (e.g. "Control", "Variant 1"), or nil if not enrolled
let variant = await mida.getExperiment(experimentKey: "checkout-flow", distinctId: userId)
// Events
await mida.setEvent(
eventName: "purchase",
distinctId: userId,
properties: ["revenue": 49.99, "currency": "USD"]
)
// Visitor attributes (standard keys: "name", "email", "company")
await mida.setAttribute(distinctId: userId, properties: ["plan": "pro"])
// Feature flags (each call loads the latest flags from the API)
let darkMode = await mida.isFeatureEnabled(key: "dark-mode", distinctId: userId)
let allFlags = await mida.getFeatureFlags(distinctId: userId)Use a stable distinctId per user (account ID, or a persisted anonymous ID). Call these methods from an async context (e.g. Task { }, or async functions).
For testing or staging:
let mida = Mida(projectKey: "YOUR_PROJECT_KEY", apiHost: "https://api.mida.so")| Method | Description |
|---|---|
getExperiment(experimentKey:distinctId:) |
Returns assigned variant string, or nil if not enrolled. |
setEvent(eventName:distinctId:properties:) |
Tracks a named event; optional JSON-serializable properties. |
setAttribute(distinctId:properties:) |
Updates visitor profile fields. |
isFeatureEnabled(key:distinctId:) |
true if the flag is enabled for the user (optional distinctId for targeting). |
getFeatureFlags(distinctId:) |
Returns all enabled flag keys for the user. |
On failure, methods return nil, false, or [] without throwing (check your integration if you need error reporting).
isFeatureEnabled and getFeatureFlags POST to the server on each call so you always get current flags. They do not cache results like the mida-node client’s cache + reload flow.
A SwiftUI demo that exercises the SDK in the simulator is in the monorepo at ios-demo-app/ (open MidaDemo.xcodeproj).
cd /path/to/ios-sdk
swift testOptional integration tests (real API) need a project key:
export MIDA_PROJECT_KEY="your_project_key"
swift test- Mida Node.js SDK — server-side JavaScript
- Android: see the android-sdk in this monorepo