Skip to main content

Installation

Swift Package Manager

Add Supabase Swift to your Package.swift:

Xcode

  1. In Xcode, go to File → Add Package Dependencies
  2. Enter the repository URL: https://github.com/supabase/supabase-swift
  3. Select the version and add to your target

Initializing

Create a Supabase client to interact with your database.
URL
required
The unique Supabase URL for your project.
String
required
The Supabase anon key for your project.
SupabaseClientOptions
Optional configuration parameters.

Database Operations

Select Data

Query data from your tables.
[T]
The returned rows from the query, decoded to your model type.

Define Models

Select with Filters

Select Specific Columns

Common Filters

Insert Data

Insert rows into your tables.
Encodable | [Encodable]
required
The values to insert. Can be a single object or an array of objects.

Insert Multiple Rows

Update Data

Update existing rows in your tables.
Encodable
required
The values to update.

Upsert Data

Insert or update rows based on unique constraints.

Delete Data

Delete rows from your tables.

Authentication

Sign Up

Create a new user account.
String
required
The user’s email address.
String
required
The user’s password.
[String: AnyJSON]
Additional user metadata.
URL
A URL to redirect to after signup.
AuthResponse

Sign In

Sign in an existing user.

Sign Out

Sign out the current user.

Get Session

Get the current session.
Session
The current session object.

Get User

Get the current user.
User
The current user object.

Auth State Changes

Listen to authentication state changes.

Storage

Upload File

Upload a file to a storage bucket.
String
required
The file path including the file name.
Data
required
The file data to upload.
FileOptions
Upload options.

Download File

Download a file from storage.
String
required
The file path to download.
Data
The file data.

List Files

List all files in a bucket.

Delete Files

Delete files from storage.

Get Public URL

Get the public URL for a file.

Realtime

Subscribe to Changes

Listen to database changes in realtime.
PostgresAction.Type
required
The database action to listen for: InsertAction, UpdateAction, DeleteAction, or AnyAction.
String
required
The database schema to listen to.
String
required
The table to listen to.
(T) -> Void
required
Function to call when an event occurs.

Unsubscribe

Stop listening to changes.

Edge Functions

Invoke Function

Invoke a Supabase Edge Function.
String
required
The name of the Edge Function to invoke.
FunctionInvokeOptions
Function invocation options.
T
The response data from the function, decoded to your model type.

Error Handling

Handle errors using do-catch blocks:

SwiftUI Integration

Use Supabase with SwiftUI’s async/await:

Additional Resources

GitHub Repository

View the source code and contribute

Swift Package Index

View package details and documentation