Skip to main content
← All platforms
Quickstart

Swift

SheepitKit, the Swift package for iOS, iPadOS, macOS, tvOS and watchOS. It tracks events, reads flags and experiments, and captures crashes.

Package
SheepitKit
Runs on
iOS 16+ · macOS 13+ · tvOS 16+ · watchOS 9+

Get an API key

Don't have an account yet? Create one, free. Then open Settings → API Keys in the dashboard and copy the publishable key (lp_pub_…). It is safe to ship inside a browser or app bundle.

Install

In Xcode, choose File → Add Package Dependencies…, paste the URL below, and set the Dependency Rule to Exact Version 0.6.0.

URL
https://github.com/goatech-ai/sheepit-swift.git

Or, in Package.swift:

Package.swift
dependencies: [
    // exact: — the mirror's 1.x tags are OLDER code exporting SheepitSDK, not
    // SheepitKit, and semver ranks them highest. Never take a range that reaches them.
    .package(url: "https://github.com/goatech-ai/sheepit-swift.git", exact: "0.6.0"),
],
targets: [
    .target(
        name: "MyApp",
        dependencies: [.product(name: "SheepitKit", package: "sheepit-swift")]
    ),
]

Initialize and send your first event

MyApp.swift
import SheepitKit

let sheepit = SheepitClient.create(config: .init(
    apiKey: "lp_pub_..."
))

sheepit.track("signup_completed", properties: ["plan": "pro"])

Read a flag and an experiment

swift
// Returns the default until the first config fetch lands.
let showNewCheckout = sheepit.flag("new_checkout", default: .bool(false)).boolValue == true

let variant = sheepit.experiment("pricing_page").variant

Identify users

swift
// After login:
sheepit.identify(userId: "user_123")

// identify() takes no traits. Track the value for dashboards and
// metrics — event properties are NOT evaluable by flag rules; use
// group membership (user_group) to target on it:
sheepit.track("plan_selected", properties: ["plan": "pro"])

// On logout:
sheepit.reset()

Check that it worked

Run the app, then open Events in the dashboard. The signup_completed event shows up within about a minute.

Worth knowing

  • Pin the exact version. The repository also has older 1.0.x tags, which Xcode's default "Up to Next Major" rule would pick. They contain an older SDK with a different product name.
  • The SDK refreshes config in the background (configRefreshInterval, 5 minutes by default), so a flag change is not instant on a running app. Lower the interval if you need changes to land sooner.
  • Crash capture is on by default. Performance monitoring is off until you turn it on in the config.
  • Events are tagged with your app's CFBundleShortVersionString unless you pass appVersion.
  • Self-hosted install? Add apiUrl: "https://<your-install>/api" to the config. The docs inside your install's dashboard show the exact value.
Swift quickstart | Sheepit