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
| Function | Parameters | Returns | Description |
|---|---|---|---|
DeployRamp.initialize | _ config: Config | async throws | Initialize the SDK. Pass Config(publicToken: "..."). Must be called with try await. |
DeployRamp.flag | _ name: String, traitOverrides: [String: String]? = nil | Bool | Evaluate a feature flag, optionally with trait overrides. |
DeployRamp.setTraits | _ traits: [String: String] | Void | Set traits for flag evaluation. |
DeployRamp.report | _ error: Error, flagName: String? = nil, traitOverrides: [String: String]? = nil | Void | Report an error, optionally associated with a specific flag. |
DeployRamp.close | none | Void | Flush pending events and release resources. |