Skip to content

Commit 7b5c60f

Browse files
committed
Documentation edits made through Mintlify web editor
1 parent f117e22 commit 7b5c60f

File tree

1 file changed

+46
-32
lines changed

1 file changed

+46
-32
lines changed

client-sdk-references/swift.mdx

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,33 @@ sidebarTitle: "Overview"
44
---
55

66
<Note>
7-
The PowerSync Swift SDK is currently in an alpha release. It is not suitable for production use at this stage unless you've tested your use cases extensively. Breaking changes are still likely to occur.
7+
The PowerSync Swift SDK is currently in an alpha release. It is not suitable for production use at this stage unless you've tested your use cases extensively. Breaking changes are still likely to occur.
88
</Note>
99

1010
## Kotlin Multiplatform -> Native Swift SDK
1111

1212
This SDK is an extension of the [Kotlin Multiplatform SDK](https://github.com/powersync-ja/powersync-kotlin), and utilizes the API tool [SKIE](https://skie.touchlab.co/) to generate and publish a [PowerSync SDK](https://github.com/powersync-ja/powersync-kotlin/tree/main/PowerSync) that can be used in a standalone Swift app. Further details about this configuration can be found in our blog [here](https://www.powersync.com/blog/using-kotlin-multiplatform-with-kmmbridge-and-skie-to-publish-a-native-swift-sdk).
1313

14-
<Info>
15-
**Demo App**
14+
For the beta, we are moving away from this Kotlin-based architecture towards more Swift-native APIs. For the stable release, will are planning a fully native Swift SDK.
1615

17-
We recommend the [Supabase Todo List Demo](https://github.com/powersync-ja/powersync-kotlin-swift-demo) app as a starting point for using the Swift SDK. See the README for details to run it.
18-
</Info>
16+
<Tip>
17+
**Demo App**
18+
19+
We recommend the [Supabase Todo List Demo](https://github.com/powersync-ja/powersync-kotlin-swift-demo) app as a starting point for using the Swift SDK. See the README for details to run it.
20+
</Tip>
1921

2022
### SDK Features
2123

2224
* Provides real-time streaming of database changes.
25+
2326
* Offers direct access to the SQLite database, enabling the use of SQL on both client and server sides.
27+
2428
* Operations are asynchronous by default, ensuring the user interface remains unblocked.
29+
2530
* Supports concurrent database operations, allowing one write and multiple reads simultaneously.
31+
2632
* Enables subscription to queries for receiving live updates.
33+
2734
* Eliminates the need for client-side database migrations as these are managed automatically.
2835

2936
## Installation
@@ -61,41 +68,42 @@ let package = Package(
6168
)
6269
```
6370

64-
2. Using Xcode:
71+
1. Using Xcode:
72+
<Frame>
73+
<img src="/images/swift.avif" />
74+
</Frame>
75+
<Frame>
76+
<img src="/images/image (1).png" />
77+
</Frame>
6578

66-
1. Follow [this](https://developer.apple.com/documentation/xcode/adding-package-dependencies-to-your-app#Add-a-package-dependency) guide to add a package to your project.
67-
2. When searching for the package use [https://github.com/powersync-ja/powersync-kotlin.git](https://github.com/powersync-ja/powersync-kotlin.git) as the URL and include the exact version `1.0.0-BETA5.0` as shown below:
79+
1. Do the same for `power-sqlite-core-swift` using [https://github.com/powersync-ja/powersync-sqlite-core-swift.git](https://github.com/powersync-ja/powersync-kotlin.git) and choose a range between `0.3.1` and `0.4.0` as shown below:
6880

69-
<Frame>
70-
71-
<img src="/images/swift.avif"></img>
72-
</Frame>
81+
1) Follow [this](https://developer.apple.com/documentation/xcode/adding-package-dependencies-to-your-app#Add-a-package-dependency) guide to add a package to your project.
7382

74-
3. Do the same for `power-sqlite-core-swift` using [https://github.com/powersync-ja/powersync-sqlite-core-swift.git](https://github.com/powersync-ja/powersync-kotlin.git) and choose a range between `0.3.1` and `0.4.0` as shown below:
75-
76-
<Frame>
77-
<img src="/images/image (1).png"></img>
78-
</Frame>
83+
2) When searching for the package use [https://github.com/powersync-ja/powersync-kotlin.git](https://github.com/powersync-ja/powersync-kotlin.git) as the URL and include the exact version `1.0.0-BETA5.0` as shown below:
7984

8085
<Note>
81-
Use the exact version for `powersync-kotlin` as we are actively making changes to the Swift SDK which could result in breaking changes. The version history can be found [here](https://central.sonatype.com/artifact/com.powersync/core/versions).
86+
Use the exact version for `powersync-kotlin` as we are actively making changes to the Swift SDK which could result in breaking changes. The version history can be found [here](https://central.sonatype.com/artifact/com.powersync/core/versions).
8287
</Note>
8388

8489
## Getting Started
8590

8691
Before implementing the PowerSync SDK in your project, make sure you have completed these steps:
8792

8893
* Signed up for a PowerSync Cloud account ([here](https://accounts.journeyapps.com/portal/get-started?powersync=true)) or [self-host PowerSync](/self-hosting/getting-started).
94+
8995
* [Configured your backend database](/installation/database-setup) and connected it to your PowerSync instance.
96+
9097
* [Installed](/client-sdk-references/swift#installation) the PowerSync SDK.
9198

92-
### 1\. Define the Schema
99+
### 1. Define the Schema
93100

94101
The first step is defining the schema for the local SQLite database, which is provided to the `PowerSyncDatabase` constructor via the `schema` parameter. This schema represents a "view" of the downloaded data. No migrations are required — the schema is applied directly when the PowerSync database is constructed.
95102

96103
The types available are `text`, `integer` and `real`. These should map directly to the values produced by the [Sync Rules](/usage/sync-rules). If a value doesn't match, it is cast automatically.
97104

98105
**Example**:
106+
99107
```swift
100108
import Foundation
101109
import PowerSync
@@ -148,10 +156,10 @@ let AppSchema = Schema(tables: [lists, todos])
148156
```
149157

150158
<Info>
151-
**Note**: No need to declare a primary key `id` column, as PowerSync will automatically create this.
159+
**Note**: No need to declare a primary key `id` column, as PowerSync will automatically create this.
152160
</Info>
153161

154-
### 2\. Instantiate the PowerSync Database
162+
### 2. Instantiate the PowerSync Database
155163

156164
Next, you need to instantiate the PowerSync database — this is the core managed database.
157165

@@ -172,20 +180,22 @@ var db = PowerSyncDatabase(
172180
)
173181
```
174182

175-
### 3\. Integrate with your Backend
183+
### 3. Integrate with your Backend
176184

177185
Create a connector to integrate with your backend. The PowerSync backend connector provides the connection between your application backend and the PowerSync managed database.
178186

179187
It is used to:
180188

181189
1. Retrieve an auth token to connect to the PowerSync instance.
190+
182191
2. Apply local changes on your backend application server (and from there, to Postgres)
183192

184193
Accordingly, the connector must implement two methods:
185194

186-
1. `PowerSyncBackendConnector.fetchCredentials` \- This is called every couple of minutes and is used to obtain credentials for your app's backend API. -> See [Authentication Setup](/installation/authentication-setup) for instructions on how the credentials should be generated.
187-
2. `PowerSyncBackendConnector.uploadData` \- Use this to upload client-side changes to your app backend.
188-
\-> See [Writing Client Changes](/installation/app-backend-setup/writing-client-changes) for considerations on the app backend implementation.
195+
1. `PowerSyncBackendConnector.fetchCredentials` - This is called every couple of minutes and is used to obtain credentials for your app's backend API. -> See [Authentication Setup](/installation/authentication-setup) for instructions on how the credentials should be generated.
196+
197+
2. `PowerSyncBackendConnector.uploadData` - Use this to upload client-side changes to your app backend.
198+
-> See [Writing Client Changes](/installation/app-backend-setup/writing-client-changes) for considerations on the app backend implementation.
189199

190200
**Example**:
191201

@@ -218,7 +228,7 @@ class MyConnector: PowerSyncBackendConnector {
218228
```
219229

220230
<Info>
221-
If you are using **Supabase**, you can use [SupabaseConnector.swift](https://github.com/powersync-ja/powersync-kotlin-swift-demo/blob/main/PowerSyncExample/PowerSync/SupabaseConnector.swift) as a starting point.
231+
If you are using **Supabase**, you can use [SupabaseConnector.swift](https://github.com/powersync-ja/powersync-kotlin-swift-demo/blob/main/PowerSyncExample/PowerSync/SupabaseConnector.swift) as a starting point.
222232
</Info>
223233

224234
## Using PowerSync: CRUD functions
@@ -227,11 +237,15 @@ Once the PowerSync instance is configured you can start using the SQLite DB func
227237

228238
The most commonly used CRUD functions to interact with your SQLite data are:
229239

230-
* [PowerSyncDatabase.get](/client-sdk-references/swift#fetching-a-single-item) \- get (SELECT) a single row from a table.
231-
* [PowerSyncDatabase.getOptional](/client-sdk-references/swift#fetching-a-single-item) \- get (SELECT) a single row from a table and return `null` if not found.
232-
* [PowerSyncDatabase.getAll](/client-sdk-references/swift#querying-items-powersync-getall) \- get (SELECT) a set of rows from a table.
233-
* [PowerSyncDatabase.watch](/client-sdk-references/swift#watching-queries-powersync-watch) \- execute a read query every time source tables are modified.
234-
* [PowerSyncDatabase.execute](/client-sdk-references/swift#mutations-powersync-execute) \- execute a write (INSERT/UPDATE/DELETE) query.
240+
* [PowerSyncDatabase.get](/client-sdk-references/swift#fetching-a-single-item) - get (SELECT) a single row from a table.
241+
242+
* [PowerSyncDatabase.getOptional](/client-sdk-references/swift#fetching-a-single-item) - get (SELECT) a single row from a table and return `null` if not found.
243+
244+
* [PowerSyncDatabase.getAll](/client-sdk-references/swift#querying-items-powersync-getall) - get (SELECT) a set of rows from a table.
245+
246+
* [PowerSyncDatabase.watch](/client-sdk-references/swift#watching-queries-powersync-watch) - execute a read query every time source tables are modified.
247+
248+
* [PowerSyncDatabase.execute](/client-sdk-references/swift#mutations-powersync-execute) - execute a write (INSERT/UPDATE/DELETE) query.
235249

236250
### Fetching a Single Item ( PowerSync.get / PowerSync.getOptional)
237251

@@ -329,4 +343,4 @@ func deleteTodo(id: String) async throws {
329343
return
330344
})
331345
}
332-
```
346+
```

0 commit comments

Comments
 (0)