Files
supabase/apps/docs/content/guides/getting-started/quickstarts/ios-swiftui.mdx
Miranda Limonczenko 1bdb8d849f docs: apply the quickstart template to the remaining quickstarts (#54502)
Closes DOCS-1616

## Problem

The remaining quickstarts don't follow the [quickstart
template](https://github.com/supabase/supabase/blob/docs/quickstart-template/apps/docs/style-guide/templates/quickstart.md)
either.

## Solution

- **Heading IDs:** each numbered step ends with the template's ID, such
as `[#create-the-client]`.
- **Heading wording:** eight headings now use the template's wording,
such as `Create the Supabase client`.
- **Style:** the prose follows the word list and elements rules.

**Not changed:** RedwoodJS, Spring Boot, and Refine. DOCS-1624 covers
them.

**Before and after:** numbered headings that use the template's wording.

| Page | Before | After |
| --- | --- | --- |
| iOS | 5/8 | 6/8 |
| Kotlin | 4/8 | 5/8 |
| Flask, Flutter, Unity | 5/7 | 6/7 |
| Expo | 6/7 | 7/7 |
| Reflex | 7/7 | 7/7 |
| Laravel | 3/7 | 3/7 |
| Rails | 3/6 | 3/6 |

**Possible errors, not changed:**

- The iOS page opens **Xcode > New Project > iOS > App**. Xcode's menu
might be **File > New > Project**.
- The Vue page says to drop a type import that `supabaseClient.ts`
doesn't have.

## Preview links

| Page | Preview |
| --- | --- |
| Flask |
[Preview](https://docs-git-docs-quickstart-rework-other-supabase.vercel.app/docs/guides/getting-started/quickstarts/flask)
|
| Reflex |
[Preview](https://docs-git-docs-quickstart-rework-other-supabase.vercel.app/docs/guides/getting-started/quickstarts/reflex)
|
| Expo React Native |
[Preview](https://docs-git-docs-quickstart-rework-other-supabase.vercel.app/docs/guides/getting-started/quickstarts/expo-react-native)
|
| Flutter |
[Preview](https://docs-git-docs-quickstart-rework-other-supabase.vercel.app/docs/guides/getting-started/quickstarts/flutter)
|
| iOS SwiftUI |
[Preview](https://docs-git-docs-quickstart-rework-other-supabase.vercel.app/docs/guides/getting-started/quickstarts/ios-swiftui)
|
| Kotlin |
[Preview](https://docs-git-docs-quickstart-rework-other-supabase.vercel.app/docs/guides/getting-started/quickstarts/kotlin)
|
| Unity |
[Preview](https://docs-git-docs-quickstart-rework-other-supabase.vercel.app/docs/guides/getting-started/quickstarts/unity)
|
| Laravel |
[Preview](https://docs-git-docs-quickstart-rework-other-supabase.vercel.app/docs/guides/getting-started/quickstarts/laravel)
|
| Ruby on Rails |
[Preview](https://docs-git-docs-quickstart-rework-other-supabase.vercel.app/docs/guides/getting-started/quickstarts/ruby-on-rails)
|

## Review category (docs PRs only)

<!--
If this PR changes docs and you're on the Supabase team, select one
category.
PRs from forks are always reviewed as Low, so you can skip this section.
-->

- [ ] Critical: needs a review as soon as possible
- [ ] Urgent: the feature ships soon, or it's blocking something else
- [ ] Moderate: good to have soon, not urgent
- [ ] Low: get to it when you can

## Review instructions

1. Open the [Kotlin
preview](https://docs-git-docs-quickstart-rework-other-supabase.vercel.app/docs/guides/getting-started/quickstarts/kotlin)
and click **Create the Supabase client** in the table of contents. The
URL ends in `#create-the-client`.
2. Open the [Laravel
preview](https://docs-git-docs-quickstart-rework-other-supabase.vercel.app/docs/guides/getting-started/quickstarts/laravel)
and click the **Run the database migrations** link in step 4. The page
scrolls to step 7.

## Checklist

Check all before review:

- [ ] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [ ] If I wrote a new docs topic or edited an existing topic, I used
the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs
[style
guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
2026-12-03 14:40:59 -08:00

122 lines
4.0 KiB
Plaintext

---
title: 'Use Supabase with iOS and SwiftUI'
subtitle: 'Learn how to create a Supabase project, add some sample data to your database, and query the data from an iOS app.'
breadcrumb: 'Framework Quickstarts'
---
<AiPrompt id="ios-swiftui" />
<$Partial path="quickstart_db_setup.mdx" />
## 3. Create an iOS SwiftUI app with Xcode [#create-an-app]
Select the **Xcode > New Project > iOS > App** menu item.
## 4. Set up AI tooling (optional) [#set-up-ai-tooling]
<$Partial path="quickstart_ai_tooling.mdx" />
## 5. Install the Supabase client library [#install-the-client-library]
Add the [supabase-swift](https://github.com/supabase/supabase-swift) package to your app using the Swift Package Manager.
In Xcode, navigate to **File > Add Package Dependencies...** and enter the repository URL `https://github.com/supabase/supabase-swift` in the search bar. For detailed instructions, see Apple's [tutorial on adding package dependencies](https://developer.apple.com/documentation/xcode/adding-package-dependencies-to-your-app).
Add the `Supabase` package product as a dependency of your app target.
## 6. Create the Supabase client [#create-the-client]
Create a `Supabase.swift` file and initialize a Supabase client using your project URL and publishable key. Get them from the following helper, or from the project [**Connect** panel](/dashboard/project/_?showConnect=true&framework=swift&connectTab=mobiles):
<Button variant="primary" asChild>
<a href="/dashboard/project/_?showConnect=true&connectTab=mobiles&framework=swift">
Open Connect panel
</a>
</Button>
```swift name=Supabase.swift
import Foundation
import Supabase
let supabase = SupabaseClient(
supabaseURL: URL(string: "YOUR_SUPABASE_URL")!,
supabaseKey: "YOUR_SUPABASE_PUBLISHABLE_KEY"
)
```
<$Partial path="api_settings.mdx" variables={{ "framework": "swift", "tab": "mobiles" }} />
<$Partial path="quickstart_mobile_env_note.mdx" />
## 7. Create a data model for instruments [#create-a-data-model-for-instruments]
Create a decodable struct to deserialize the data from the database.
Add the following code to a file named `Instrument.swift`.
```swift name=Instrument.swift
struct Instrument: Decodable, Identifiable {
let id: Int
let name: String
}
```
## 8. Query data from the app [#query-data]
Use a `task` to fetch the data from the database and display it using a `List`.
Replace the default `ContentView` with the following code.
```swift name=ContentView.swift
import SwiftUI
import Supabase
struct ContentView: View {
@State var instruments: [Instrument] = []
@State var errorMessage: String?
@State var isLoading = true
var body: some View {
List(instruments) { instrument in
Text(instrument.name)
}
.overlay {
if let errorMessage {
Text("Error loading instruments: \(errorMessage)")
} else if isLoading {
ProgressView()
}
}
.task {
do {
instruments = try await supabase.from("instruments").select().execute().value
} catch {
errorMessage = error.localizedDescription
}
isLoading = false
}
}
}
```
## 9. Start the app [#start-the-app]
In Xcode, press `Cmd+R` to run the app on a simulator or a physical device.
## 10. Set up deep links (optional) [#set-up-deep-links]
To implement authentication features such as magic links or OAuth, set up deep links that redirect users back to your app. For instructions on configuring custom URL schemes for your iOS app, see [Native Mobile Deep Linking](/docs/guides/auth/native-mobile-deep-linking?platform=swift).
<$Partial path="quickstart_going_to_production.mdx" />
## Next steps
Build on this app with the following resources:
- Learn how to build a complete user management app with authentication in the [Swift tutorial](/docs/guides/getting-started/tutorials/with-swift)
- Explore the [supabase-swift](https://github.com/supabase/supabase-swift) library on GitHub
- [Insert more data](/docs/guides/database/import-data) into your database
- Upload and serve static files using [Storage](/docs/guides/storage)