Swift SDK

The DeployRamp Swift SDK lets you evaluate feature flags, report errors, and manage traits from any Swift application. All methods are static on the DeployRamp class.

Installation

Add the package dependency to your Package.swift:

.package(url: "https://github.com/deployramp/deployramp-swift", from: "0.1.0")

Initialization

Initialize the SDK with your public token before evaluating any flags. Note that initialize is async and must be called with try await:

import DeployRamp

try await DeployRamp.initialize(Config(publicToken: "pk_live_abc123"))

Evaluating Flags

Call DeployRamp.flag() with the flag name to check whether a feature is enabled. You can optionally pass trait overrides:

if DeployRamp.flag("new-checkout") {
    // new checkout flow
}

// With trait overrides
if DeployRamp.flag("new-checkout", traitOverrides: ["plan": "enterprise"]) {
    // enterprise-only checkout flow
}

Setting Traits

Traits are key-value pairs that describe the current user or environment. They influence flag evaluation on the server:

DeployRamp.setTraits([
    "plan": "pro",
    "region": "us-east-1",
])

Error Reporting

Report caught errors so DeployRamp can correlate them with flag rollouts and trigger automatic rollbacks when needed:

do {
    try processPayment()
} catch {
    DeployRamp.report(error, flagName: "new-checkout")
}

Shutdown

Call close() when your application is shutting down to flush any pending events and release resources:

DeployRamp.close()

API Reference

FunctionParametersReturnsDescription
DeployRamp.initialize_ config: Configasync throwsInitialize the SDK. Pass Config(publicToken: "..."). Must be called with try await.
DeployRamp.flag_ name: String, traitOverrides: [String: String]? = nilBoolEvaluate a feature flag, optionally with trait overrides.
DeployRamp.setTraits_ traits: [String: String]VoidSet traits for flag evaluation.
DeployRamp.report_ error: Error, flagName: String? = nil, traitOverrides: [String: String]? = nilVoidReport an error, optionally associated with a specific flag.
DeployRamp.closenoneVoidFlush pending events and release resources.

We use cookies to analyze site usage and improve your experience.