shovelbasedocs

shovelbase-swift — Swift

shovelbase-swift is the client for Apple platforms (iOS, macOS, tvOS, watchOS): database queries, auth, storage, edge functions, signals, and feature flags. Add it from shovelbase.com/swift. Three library products — Shovelbase (the full client), ShovelbaseSignals (signals only), and ShovelbaseFlags (flags only) — the latter two each a single dependency-free file.

setup
import Shovelbase
// Once, at launch (e.g. in your App init). URL + anon key: Project Settings API.
let shovelbase = Shovelbase.createClient(
url: "https://<project-ref>.shovelbase.com", // SHOVELBASE_URL
key: "<SHOVELBASE_ANON_KEY>"
)

Database

Swift
struct Club: Decodable { let id: Int; let name: String; let distance: Int }
let clubs: [Club] = try await shovelbase.from("clubs")
.select()
.eq("in_bag", value: true)
.order("distance", ascending: false)
.execute()
.value
try await shovelbase.from("clubs").insert(["name": "7 iron", "distance": 165]).execute()

Auth

Swift
try await shovelbase.auth.signUp(email: email, password: password)
try await shovelbase.auth.signIn(email: email, password: password)
let user = try await shovelbase.auth.session.user

Storage & functions

Swift
try await shovelbase.storage.from("avatars")
.upload("\(user.id).png", data: imageData)
let reply: ChatReply = try await shovelbase.functions
.invoke("chat", options: .init(body: ["messages": messages]))

Signals

Every client has a signals handle; events are persisted to disk (so they survive app kills) and flushed on a timer, at batch size, and when the app is backgrounded. See Signals.

Swift
shovelbase.signals.identify(user.id.uuidString)
shovelbase.signals.track("signup", properties: ["plan": "pro"])

Feature flags

Every client has a flags handle too. See Feature Flags.

Swift
if await shovelbase.flags.isEnabled("new-checkout") { /* */ }

Realtime subscriptions (.channel()) are not supported yet; database, auth, storage, functions, signals, and feature flags all work.