Skip to content

Search is only available in production builds. Try building and previewing the site to test it out locally.

Swift SDK

The Swift SDK provides typed access to Reactor capabilities for iOS, macOS, and server-side Swift applications.

Add the package to your Package.swift:

dependencies: [
.package(url: "https://github.com/reactor-cloud/reactor-cloud", from: "0.1.0"),
],
targets: [
.target(name: "MyApp", dependencies: [
.product(name: "ReactorClient", package: "reactor-cloud"),
.product(name: "ReactorAuth", package: "reactor-cloud"),
.product(name: "ReactorData", package: "reactor-cloud"),
]),
]

Or in Xcode: File → Add Package Dependencies and enter the repository URL.

import ReactorClient
let reactor = ReactorClient(
url: URL(string: "https://api.reactor.cloud")!,
token: ProcessInfo.processInfo.environment["REACTOR_TOKEN"]
)
import ReactorAuth
let auth = ReactorAuth(client: reactor)
// Sign in
let session = try await auth.signIn(
email: "user@example.com",
password: "secure-password"
)
// Get current user
let user = try await auth.getUser()
import ReactorData
let data = ReactorData(client: reactor)
// Fetch posts
let posts: [Post] = try await data
.from("posts")
.select()
.eq("published", value: true)
.order("created_at", ascending: false)
.limit(20)
.execute()
// Insert
let newPost: Post = try await data
.from("posts")
.insert(PostInsert(title: "Hello", body: "World"))
.select()
.single()
.execute()
import ReactorStorage
let storage = ReactorStorage(client: reactor)
// Upload
try await storage
.from("avatars")
.upload(path: "user-123.png", data: imageData)
// Download
let data = try await storage
.from("avatars")
.download(path: "user-123.png")
import ReactorFunctions
let functions = ReactorFunctions(client: reactor)
struct OrderPayload: Codable {
let orderId: String
}
let result = try await functions.invoke(
"process-order",
body: OrderPayload(orderId: "123")
)

The Swift SDK includes OpenAPI-generated types. Regenerate from the spec:

Terminal window
cd reactor-cloud/sdks/swift
./scripts/generate-openapi.sh

Swift SDK source: reactor-cloud/sdks/swift/