Use Supabase with iOS and SwiftUI
Learn how to create a Supabase project, add some sample data to your database, and query the data from an iOS app.
Set up a Supabase project with sample data
Create a new project in the Supabase Dashboard.
After your project is ready, create a table in your Supabase database using the SQL Editor in the Dashboard. Use the following SQL statement to create a countries
table with some sample data.
Create an iOS SwiftUI app with Xcode
Open Xcode > New Project > iOS > App. You can skip this step if you already have a working app.
Install the Supabase client library
Install Supabase package dependency using Xcode by following Apple's tutorial.
Make sure to add Supabase
product package as dependency to the application.
Initialize the Supabase client
Create a new Supabase.swift
file add a new supabase instance using your project URL and public API (anon) key:
Project URL
Anon key
Create a data model for countries
Create a decodable struct to deserialize the data from the database.
Add the following code to a new file named Country.swift
.
Query data from the app
Use a task
to fetch the data from the database and display it using a List
.
Replace the default ContentView
with the following code.
Start the app
Run the app on a simulator or a physical device by hitting Cmd + R
on Xcode.