supabase/supabase-swift
حول
SDK بلغة Swift لـ Supabase. يتيح الاستعلام عن قاعدة بيانات Supabase، والاشتراك في الأحداث الفورية، ورفع الملفات وتنزيلها، واستعراض أمثلة Swift، واستدعاء دوال PostgreSQL عبر RPC ودوال Supabase Edge، والاستعلام عن pgvector.
البيانات والتحليلاتالنمو المقاس للنجوم
- خلال 24 ساعة
- +١
- خلال 7 أيام
- +٣
- خلال 15 يومًا
- +٣
- خلال شهر
- +٣
تغيّر صافي النجوم خلال فترات متداخلة، وليس مجموعًا يوميًا. تبقى القياسات المفقودة فارغة. النجوم تقيس الاهتمام لا جودة البرمجيات.
README.md
الأصلSupabase Swift SDK
Libraries
| Library | Description |
|---|---|
| Supabase | Full client — includes all libraries below |
| Auth | User authentication and session management |
| PostgREST | Query your Postgres database via REST |
| Realtime | Subscribe to database changes over WebSocket |
| Storage | Manage files and objects |
| Functions | Invoke Supabase Edge Functions |
Quick Start
Requirements
- iOS 16.0+ / macOS 13.0+ / tvOS 16+ / watchOS 9+ / visionOS 1+
- Xcode 26.0+
- Swift 6.2+
[!IMPORTANT] Check the Support Policy to learn when dropping Xcode, Swift, and platform versions will not be considered a breaking change.
Installation
Add supabase-swift as a Swift Package Manager dependency:
let package = Package(
...
dependencies: [
.package(
url: "https://github.com/supabase/supabase-swift.git",
from: "3.0.0-alpha.3"
),
],
targets: [
.target(
name: "YourTargetName",
dependencies: [
.product(name: "Supabase", package: "supabase-swift")
]
)
]
)
If you're using Xcode, use this guide to add supabase-swift to your project. Use https://github.com/supabase/supabase-swift.git for the URL when Xcode asks.
You can also add individual libraries (Auth, Functions, PostgREST, PostgrestMacros, Realtime, Storage, StorageIceberg) instead of the full Supabase product.
PostgrestMacros and StorageIceberg are opt-in: the Supabase product does not include them. StorageIceberg manages the Apache Iceberg tables in Storage analytics buckets. It is experimental: import it with @_spi(Experimental) import StorageIceberg.
Initialize the client
let client = try SupabaseClient(
supabaseURL: URL(string: "https://xyzcompany.supabase.co")!,
supabaseKey: "your-publishable-key"
)
Initialize with custom options
let client = try SupabaseClient(
supabaseURL: URL(string: "https://xyzcompany.supabase.co")!,
supabaseKey: "your-publishable-key",
configuration: SupabaseClient.Configuration(
database: .init(
schema: "public"
),
auth: .init(
storage: MyCustomAuthStorage()
),
global: .init(
headers: [HTTPField.Name("x-my-custom-header")!: "my-app-name"],
http: .init(transport: URLSessionTransport(session: URLSession.myCustomSession))
)
)
)
Sign in and track the session
// Sign in. The session is stored for you.
try await client.auth.signIn(email: "[email protected]", password: "secret")
// React to every change: sign-in, sign-out, token refresh, and more.
for await change in client.auth.events() {
print(change.event, change.session?.user.email ?? "signed out")
}
In SwiftUI, AuthModel (iOS 17, macOS 14, tvOS 17, watchOS 10, visionOS 1 or later) is an
@Observable view of the session. Gate your root view on its status:
@State private var auth = AuthModel(client: client.auth)
var body: some View {
switch auth.status {
case .loading: ProgressView()
case .signedOut: SignInView()
case .signedIn: HomeView()
}
}
Send every auth link that opens your app to handleRedirect. It handles OAuth callbacks,
magic links, and password-reset links, and it is safe to call twice with the same URL. A
password-reset link signs the user in, so check the result to show an "update password" screen:
.onOpenURL { url in
Task {
if case .signedIn(_, verification: .recovery)? = try await client.handleRedirect(url) {
isPasswordRecovery = true
}
}
}
On Apple platforms the session is stored in the Keychain. On iOS, tvOS, watchOS and visionOS it
stays on the device. On Linux, Android and Windows the default storage keeps the session in
memory, so pass your own AuthStorage to keep it across launches.
Query the database
struct Todo: Codable {
let id: Int
let task: String
}
// Read rows. The result decodes as the type you ask for.
let todos: [Todo] = try await client.from("todos")
.select()
.eq("is_done", value: false)
.order("id")
.execute()
.value
// Insert a row, and get it back.
let created: Todo = try await client.from("todos")
.insert(["task": "Write the docs"])
.select()
.single()
.execute()
.value
Upload a file
let avatars = client.storage.from("avatars")
try await avatars.upload(path: "user123.png", data: Data("hello".utf8))
let data = try await avatars.download(path: "user123.png").data()
Listen for Realtime messages
let channel = await client.channel("room:42")
let messages = await channel.broadcasts(event: "message")
try await channel.subscribe()
for await message in messages {
print(message)
}
Invoke an Edge Function
struct Answer: Decodable { let text: String }
// JSON in, typed JSON out
let answer: Answer = try await client.functions.invoke("ask", body: .json(["prompt": "hi"]))
// Raw response: status, headers, bytes
let response = try await client.functions.invoke("report", options: .init(method: .get))
print(response.status, response.body.count)
Stream a response
let response = try await client.functions.stream("chat", body: .json(["prompt": "hi"]))
for try await chunk in response.body {
// chunk boundaries follow the network; frame server-sent events yourself
}
Generate database types
supabase gen types --lang swift writes @Table structs for your schema:
supabase gen types --lang swift --local > Sources/App/Database.swift
It runs the supabase-typegen executable from this repository. Supabase CLI 3.3.0 and later build
it from supabase-swift's source with your own git and Swift 6.2 (Xcode 26) or newer, and cache it
per commit. By default, the CLI builds the supabase-swift version that your Package.resolved
pins. To choose another source, pass --swift-typegen-source with a version, a branch, a full
commit SHA, or a local checkout. Before the build, the CLI checks that the commit is supabase-swift's
own: the version tag must point at it, or it must be on the upstream branch. It does not build a
commit from a fork or a pull request. Windows is not supported.
Supabase CLI 3.2.0 and earlier download the prebuilt supabase-typegen from the release and do not
check its checksum. Upgrade the CLI. When those versions cannot download it, for example without
network access, they use the supabase-typegen on your PATH. For that case, each release carries
prebuilt binaries with checksums and build provenance. Install the build that matches the
supabase-swift version your project uses:
VERSION=3.0.0-alpha.3 # your supabase-swift version
ASSET=supabase-typegen-macos-universal.tar.gz # or supabase-typegen-linux-x86_64.tar.gz
URL="https://github.com/supabase/supabase-swift/releases/download/v$VERSION"
TMP=$(mktemp -d)
curl -fsSL -o "$TMP/$ASSET" "$URL/$ASSET" -o "$TMP/SHA256SUMS" "$URL/SHA256SUMS"
mkdir -p ~/.local/bin
# Optional, with the GitHub CLI: uncomment to also check the build provenance before tar runs.
# gh attestation verify "$TMP/$ASSET" --repo supabase/supabase-swift \
# --signer-workflow supabase/supabase-swift/.github/workflows/typegen-binaries.yml &&
(cd "$TMP" && if command -v sha256sum >/dev/null; then sha256sum --ignore-missing -c SHA256SUMS
else shasum -a 256 --ignore-missing -c SHA256SUMS; fi) &&
tar -xzf "$TMP/$ASSET" -C ~/.local/bin &&
~/.local/bin/supabase-typegen --version
The checksum tool (sha256sum, or shasum on macOS) checks the archive against the release's
SHA256SUMS before tar extracts it. That catches a damaged download, but SHA256SUMS comes from
the same release, so it cannot catch someone who replaces both files. The build provenance can:
uncomment the two gh attestation verify lines to check that this repository's typegen release
workflow built the archive. The attestation does not name the release version, so check that the
last line prints the version you asked for. Releases up to 3.0.0-alpha.3 have checksums but no
attestation.
Put ~/.local/bin on your PATH if it is not there yet.
On macOS, a binary you download with a browser is quarantined, and Gatekeeper blocks it. curl
does not set the quarantine flag. To clear it from a browser download, run
xattr -d com.apple.quarantine ~/.local/bin/supabase-typegen.
Additional examples are available in the Examples directory.
Documentation
- API documentation on the Swift Package Index. It has a guide for each library: getting started, error handling, standalone use, and testing with a stub transport.
- V3 migration guide, to move an app from v2.
- Examples.
CI compiles the Swift snippets in this file, except the Package.swift and SwiftUI fragments. See
DEVELOPMENT.md.
Support Policy
Xcode
We only support Xcode versions that are currently eligible for submitting apps to the App Store. Once a specific version of Xcode is no longer supported, its removal from Supabase won't be treated as a breaking change and will occur in a minor release.
Swift
The minimum supported Swift version corresponds to the minor version released with the oldest-supported Xcode version. When a Swift version reaches its end of support, it will be dropped in a minor release, and this won't be considered a breaking change.
Platforms
We maintain support for the four latest major versions of each platform, including the current version.
When a platform version is no longer supported, Supabase will drop it in a minor release, and this won't count as a breaking change. For instance, iOS 14 will no longer be supported after the release of iOS 18, allowing its removal in a minor update.
For macOS, the named yearly releases are treated as major versions for this policy, regardless of their version numbers.
[!IMPORTANT] Android, Linux and Windows work but aren't officially supported, and may stop working in future versions of the library.
Supabase Service Compatibility
The Supabase Swift SDK only guarantees compatibility with the latest release of each Supabase service, unless a minimum supported version is explicitly listed below.
Older service releases are supported on a best-effort basis, but compatibility is not guaranteed.
If you self-host Supabase, we recommend upgrading your services to their latest releases when upgrading the SDK.
| Service | Library | Server releases | Lowest supported version |
|---|---|---|---|
| Auth | Auth |
supabase/auth | Latest release |
| Storage | Storage |
supabase/storage | Latest release |
| Functions | Functions |
supabase/edge-runtime | Latest release |
| PostgREST | PostgREST |
PostgREST/postgrest | Latest release |
| Realtime | Realtime |
supabase/realtime | Latest release |
Contributing
We welcome contributions! Please see the steps below.
- Fork the repo and clone it locally.
- Create a feature branch (
git checkout -b feature/my-feature). - Make your changes and add tests.
- Run
./scripts/format.shto format Swift code. - Run
PLATFORM=IOS XCODEBUILD_ARGUMENT=test ./scripts/xcodebuild.shto verify tests pass. - Commit using Conventional Commits (e.g.
feat(auth): add PKCE support). - Open a pull request against
main.
Support
- Documentation: supabase.com/docs/reference/swift
- Community: GitHub Discussions
- Issues: GitHub Issues
- Discord: Supabase Discord
License
This project is licensed under the MIT License — see the LICENSE file for details.
Website • Documentation • Community • Twitter
استكشف مشاريع مشابهة ومرتبطة
جارٍ التحميل…