Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

docs: swift guide for connect (#27541)

hallidayoa2dc897d053b
diff --git a/apps/studio/components/interfaces/Home/Connect/Connect.constants.ts b/apps/studio/components/interfaces/Home/Connect/Connect.constants.ts
index 24bb9cec4a9..e7adce95098 100644
--- a/apps/studio/components/interfaces/Home/Connect/Connect.constants.ts
+++ b/apps/studio/components/interfaces/Home/Connect/Connect.constants.ts
@@ -206,6 +206,20 @@ export const MOBILES: ConnectionType[] = [
},
],
},
+ {
+ key: 'swift',
+ label: 'Swift',
+ icon: 'swift',
+ guideLink: 'https://supabase.com/docs/guides/getting-started/tutorials/with-swift',
+ children: [
+ {
+ key: 'supabaseswift',
+ label: 'supabase-swift',
+ children: [],
+ icon: 'supabase',
+ },
+ ],
+ },
{
key: 'androidkotlin',
label: 'Android Kotlin',
diff --git a/apps/studio/components/interfaces/Home/Connect/content/swift/supabaseswift/content.tsx b/apps/studio/components/interfaces/Home/Connect/content/swift/supabaseswift/content.tsx
new file mode 100644
index 00000000000..a22a289bccc
--- /dev/null
+++ b/apps/studio/components/interfaces/Home/Connect/content/swift/supabaseswift/content.tsx
@@ -0,0 +1,84 @@
+import type { ContentFileProps } from 'components/interfaces/Home/Connect/Connect.types'
+
+import {
+ ConnectTabs,
+ ConnectTabTriggers,
+ ConnectTabTrigger,
+ ConnectTabContent,
+} from 'components/interfaces/Home/Connect/ConnectTabs'
+import SimpleCodeBlock from 'components/to-be-cleaned/SimpleCodeBlock'
+
+const ContentFile = ({ projectKeys }: ContentFileProps) => {
+ return (
+ <ConnectTabs>
+ <ConnectTabTriggers>
+ <ConnectTabTrigger value="Supabase.swift" />
+ <ConnectTabTrigger value="Todo.swift" />
+ <ConnectTabTrigger value="ContentView.swift" />
+ </ConnectTabTriggers>
+
+ <ConnectTabContent value="Supabase.swift">
+ <SimpleCodeBlock className="swift" parentClassName="min-h-72">
+ {`
+import Foundation
+import Supabase
+
+let supabase = SupabaseClient(
+ supabaseURL: URL(string: "${projectKeys.apiUrl ?? 'your-project-url'}")!,
+ supabaseKey: "${projectKeys.anonKey ?? 'your-anon-key'}"
+)
+ `}
+ </SimpleCodeBlock>
+ </ConnectTabContent>
+
+ <ConnectTabContent value="Todo.swift">
+ <SimpleCodeBlock className="swift" parentClassName="min-h-72">
+ {`
+import Foundation
+
+struct Todo: Identifiable, Decodable {
+ var id: Int
+ var title: String
+}
+`}
+ </SimpleCodeBlock>
+ </ConnectTabContent>
+
+ <ConnectTabContent value="ContentView.swift">
+ <SimpleCodeBlock className="swift" parentClassName="min-h-72">
+ {`
+import Supabase
+import SwiftUI
+
+struct ContentView: View {
+ @State var todos: [Todo] = []
+
+ var body: some View {
+ NavigationStack {
+ List(todos) { todo in
+ Text(todo.title)
+ }
+ .navigationTitle("Todos")
+ .task {
+ do {
+ todos = try await supabase.from("todos").select().execute().value
+ } catch {
+ debugPrint(error)
+ }
+ }
+ }
+ }
+}
+
+#Preview {
+ ContentView()
+}
+
+`}
+ </SimpleCodeBlock>
+ </ConnectTabContent>
+ </ConnectTabs>
+ )
+}
+
+export default ContentFile