Skip to content

Commit 2ba40c6

Browse files
feat: update swift to beta (#57)
* feat: update swift docs to beta * chore: update * chore: remove spacing * chore: update client side * Update alpha references * Updates * Update migration-guides/mongodb-atlas.mdx --------- Co-authored-by: benitav <[email protected]> Co-authored-by: benitav <[email protected]>
1 parent cefbbd4 commit 2ba40c6

File tree

12 files changed

+84
-109
lines changed

12 files changed

+84
-109
lines changed

client-sdk-references/introduction.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ Select your client framework for the full SDK reference, getting started instruc
1616
Currently in a beta release.
1717
</Card>
1818
<Card title="Swift" icon="swift" href="/client-sdk-references/swift">
19-
Currently in an alpha release.
19+
Currently in a beta release.
2020
</Card>
2121
</CardGroup>

client-sdk-references/kotlin-multiplatform.mdx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@ sidebarTitle: Overview
1010
<Card title="Source Code" icon="github" href="https://github.com/powersync-ja/powersync-kotlin/">
1111
Refer to the powersync-kotlin repo on GitHub.
1212
</Card>
13-
<Card title="API Reference (Coming soon)" icon="book" href="https://powersync-ja.github.io/powersync-js/react-native-sdk">
13+
<Card title="API Reference (Coming soon)" icon="book" href="">
1414
A full API Reference for this SDK is not yet available. This is planned for the stable release.
1515
</Card>
1616
<Card title="Example Projects" icon="code" href="/resources/demo-apps-example-projects#kotlin-multiplatform">
1717
Gallery of example projects/demo apps built with Kotlin Multiplatform and PowerSync.
1818
</Card>
1919
</CardGroup>
2020

21+
<Note>
22+
The PowerSync Swift SDK is currently in a beta release. It is suitable for production use at this stage given you've tested your use cases extensively. Breaking changes are unlikely to occur.
23+
</Note>
24+
2125
### SDK Features
2226

2327
* Provides real-time streaming of database changes.

client-sdk-references/swift.mdx

Lines changed: 57 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
11
---
2-
title: "Swift (Alpha)"
2+
title: "Swift (Beta)"
33
sidebarTitle: "Overview"
44
---
55

6+
<CardGroup cols={3}>
7+
<Card title="Source Code" icon="github" href="https://github.com/powersync-ja/powersync-swift/">
8+
Refer to the powersync-swift repo on GitHub.
9+
</Card>
10+
<Card title="API Reference (Coming soon)" icon="book" href="">
11+
A full API Reference for this SDK is not yet available. This is planned for the stable release.
12+
</Card>
13+
<Card title="Example Projects" icon="code" href="/resources/demo-apps-example-projects#swift">
14+
Gallery of example projects/demo apps built with PowerSync and Swift.
15+
</Card>
16+
</CardGroup>
17+
618
<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.
19+
The PowerSync Swift SDK is currently in a beta release. It is suitable for production use at this stage given you've tested your use cases extensively. Breaking changes are unlikely to occur.
820
</Note>
921

1022
## Kotlin Multiplatform -> Native Swift SDK
1123

12-
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).
13-
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.
24+
The PowerSync Swift SDK currently makes use of the [PowerSync Kotlin Multiplatform SDK](https://github.com/powersync-ja/powersync-kotlin) with the API tool [SKIE](https://skie.touchlab.co/) and KMMBridge under the hood to help generate and publish a Swift package. We will move to an entirely Swift native SDK in v1 and do not expect there to be any breaking changes.
1525

1626
<Tip>
1727
**Demo App**
1828

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.
29+
We recommend the [Supabase Todo List Demo](https://github.com/powersync-ja/powersync-swift/tree/main/Demo) app as a starting point for using the Swift SDK. See the README for details to run it.
2030
</Tip>
2131

2232
### SDK Features
@@ -43,11 +53,9 @@ let package = Package(
4353
dependencies: [
4454
...
4555
.package(
46-
url: "https://github.com/powersync-ja/powersync-kotlin",
47-
exact: "1.0.0-BETA5.0"
48-
),
49-
.package(
50-
url: "https://github.com/powersync-ja/powersync-sqlite-core-swift",
56+
url: "https://github.com/powersync-ja/powersync-swift",
57+
// Exact version required while still in beta
58+
exact: "<version>"
5159
),
5260
],
5361
targets: [
@@ -56,11 +64,7 @@ let package = Package(
5664
dependencies: [
5765
.product(
5866
name: "PowerSync",
59-
package: "powersync-kotlin"
60-
),
61-
.product(
62-
name: "PowerSyncSqliteCore",
63-
package: "powersync-sqlite-core-swift"
67+
package: "powersync-swift"
6468
),
6569
]
6670
)
@@ -71,21 +75,22 @@ let package = Package(
7175
2. Using Xcode:
7276

7377
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.
74-
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:
78+
2. When searching for the package use [https://github.com/powersync-ja/powersync-swift.git](https://github.com/powersync-ja/powersync-swift.git) as the URL and include the exact version e.g. `1.0.0-Beta.x` as shown below:
7579

7680
<Frame>
77-
78-
<img src="/images/swift.avif"></img>
81+
<img src="/images/Swift-Xcode.png"></img>
7982
</Frame>
8083

81-
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:
82-
<Frame>
83-
<img src="/images/image (1).png"></img>
84-
</Frame>
84+
### Migrating from the Alpha to the Beta SDK
8585

86-
<Note>
87-
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).
88-
</Note>
86+
The beta version of this SDK introduces a Swift-native wrapper around the package generated from the Kotlin Multiplatform SDK, bringing a more Swift-native interface for developers. This results in several API updates from the more Kotlin-based alpha version. The main changes are:
87+
* The `PowerSyncDatabase` no longer needs a driver argument and it must be removed.
88+
* The interface for `PowerSyncDatabase` now uses `PowerSyncDatabaseProtocol` which may require some changes to databases uses.
89+
* If you were using `__uploadData` and `__fetchCredentials` in your `PowerSyncBackendConnector` you must remove the `__` and update the methods to `uploadData` and `fetchCredentials`.
90+
* `@MainThread` usage is no longer required and should be removed.
91+
* Implementing `SuspendTaskWrapper` for database transactions is no longer required and should be removed.
92+
93+
See the [Todo List Demo app](https://github.com/powersync-ja/powersync-swift/tree/main/Demo) as a reference.
8994

9095
## Getting Started
9196

@@ -116,44 +121,37 @@ let lists = Table(
116121
name: LISTS_TABLE,
117122
columns: [
118123
// ID column is automatically included
119-
Column(name: "name", type: ColumnType.text),
120-
Column(name: "created_at", type: ColumnType.text),
121-
Column(name: "owner_id", type: ColumnType.text)
122-
],
123-
indexes: [],
124-
localOnly: false,
125-
insertOnly: false,
126-
viewNameOverride: LISTS_TABLE
124+
.text("name"),
125+
.text("created_at"),
126+
.text("owner_id")
127+
]
127128
)
128129

129130
let todos = Table(
130131
name: TODOS_TABLE,
131132
// ID column is automatically included
132133
columns: [
133-
Column(name: "list_id", type: ColumnType.text),
134-
Column(name: "photo_id", type: ColumnType.text),
135-
Column(name: "description", type: ColumnType.text),
134+
.text("list_id"),
135+
.text("photo_id"),
136+
.text("description"),
136137
// 0 or 1 to represent false or true
137-
Column(name: "completed", type: ColumnType.integer),
138-
Column(name: "created_at", type: ColumnType.text),
139-
Column(name: "completed_at", type: ColumnType.text),
140-
Column(name: "created_by", type: ColumnType.text),
141-
Column(name: "completed_by", type: ColumnType.text)
138+
.integer("completed"),
139+
.text("created_at"),
140+
.text("completed_at"),
141+
.text("created_by"),
142+
.text("completed_by")
142143
],
143144
indexes: [
144145
Index(
145146
name: "list_id",
146147
columns: [
147-
IndexedColumn(column: "list_id", ascending: true, columnDefinition: nil, type: nil)
148+
IndexedColumn.ascending("list_id")
148149
]
149150
)
150-
],
151-
localOnly: false,
152-
insertOnly: false,
153-
viewNameOverride: TODOS_TABLE
151+
]
154152
)
155153

156-
let AppSchema = Schema(tables: [lists, todos])
154+
let AppSchema = Schema(lists, todos)
157155
```
158156

159157
<Info>
@@ -169,15 +167,11 @@ Its primary function is to record all changes in the local database, whether onl
169167
**Example**:
170168

171169
```swift
172-
// Comes from the PowerSync package
173-
let factory = DatabaseDriverFactory()
174170
// Comes from the AppSchema defined above
175171
let schema = AppSchema
176-
var db = PowerSyncDatabase(
177-
factory: factory,
172+
let db = PowerSyncDatabase(
178173
schema: schema,
179-
dbFilename: "powersync-swift.sqlite",
180-
params: [:]
174+
dbFilename: "powersync-swift.sqlite"
181175
)
182176
```
183177

@@ -204,11 +198,10 @@ Accordingly, the connector must implement two methods:
204198
import PowerSync
205199

206200
@Observable
207-
@MainActor
208201
class MyConnector: PowerSyncBackendConnector {
209202
override func fetchCredentials() async throws -> PowerSyncCredentials? {
210203
// implement fetchCredentials to obtain the necessary credentials to connect to your backend
211-
// See an example implementation in https://github.com/powersync-ja/powersync-kotlin-swift-demo/blob/main/PowerSyncExample/PowerSync/SupabaseConnector.swift
204+
// See an example implementation in https://github.com/powersync-ja/powersync-swift/blob/main/Demo/PowerSyncExample/PowerSync/SupabaseConnector.swift
212205

213206
return {
214207
endpoint: '[Your PowerSync instance URL or self-hosted endpoint]',
@@ -218,7 +211,7 @@ class MyConnector: PowerSyncBackendConnector {
218211
}
219212
}
220213

221-
override func uploadData(database: any PowerSyncDatabase) async throws {
214+
override func uploadData(database: PowerSyncDatabaseProtocol) async throws {
222215
// Implement uploadData to send local changes to your backend service
223216
// You can omit this method if you only want to sync data from the server to the client
224217
// See an example implementation under Usage Examples (sub-page)
@@ -228,10 +221,6 @@ class MyConnector: PowerSyncBackendConnector {
228221

229222
```
230223

231-
<Info>
232-
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.
233-
</Info>
234-
235224
## Using PowerSync: CRUD functions
236225

237226
Once the PowerSync instance is configured you can start using the SQLite DB functions.
@@ -311,7 +300,7 @@ func watchLists(_ callback: @escaping (_ lists: [ListContent]) -> Void ) async {
311300
)
312301
}
313302
) {
314-
callback(lists as! [ListContent])
303+
callback(lists)
315304
}
316305
}
317306
```
@@ -336,12 +325,12 @@ func updateTodo(_ todo: Todo) async throws {
336325
}
337326

338327
func deleteTodo(id: String) async throws {
339-
try await db.writeTransaction(callback: SuspendTaskWrapper {
340-
try await db.execute(
341-
sql: "DELETE FROM \(TODOS_TABLE) WHERE id = ?",
342-
parameters: [id]
343-
)
328+
try await db.writeTransaction(callback: { transaction in
329+
_ = try await transaction.execute(
330+
sql: "DELETE FROM \(TODOS_TABLE) WHERE id = ?",
331+
parameters: [id]
332+
)
344333
return
345334
})
346335
}
347-
```
336+
```

images/Swift-Xcode.png

231 KB
Loading

images/image (1).png

-248 KB
Binary file not shown.

images/swift.avif

-131 KB
Binary file not shown.

installation/client-side-setup.mdx

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The next step after configuring your database and connecting it to your PowerSyn
1818

1919
2. Write mutations to your backend
2020

21-
PowerSync currently supports apps built in [Flutter](/client-sdk-references/flutter), [React Native & Expo](/client-sdk-references/react-native-and-expo), [JavaScript Web](/client-sdk-references/javascript-web), [Kotlin Multiplatform](/client-sdk-references/kotlin-multiplatform) (beta), and [Swift](/client-sdk-references/swift) (alpha).
21+
PowerSync currently supports apps built in [Flutter](/client-sdk-references/flutter), [React Native & Expo](/client-sdk-references/react-native-and-expo), [JavaScript Web](/client-sdk-references/javascript-web), [Kotlin Multiplatform](/client-sdk-references/kotlin-multiplatform) (beta), and [Swift](/client-sdk-references/swift) (beta).
2222

2323
Please see the steps based on your app framework:
2424

@@ -175,11 +175,8 @@ Please see the steps based on your app framework:
175175
dependencies: [
176176
...
177177
.package(
178-
url: "https://github.com/powersync-ja/powersync-kotlin",
179-
exact: "1.0.0-BETA5.0"
180-
),
181-
.package(
182-
url: "https://github.com/powersync-ja/powersync-sqlite-core-swift",
178+
url: "https://github.com/powersync-ja/powersync-swift",
179+
exact: "<version>"
183180
),
184181
],
185182
targets: [
@@ -188,12 +185,8 @@ Please see the steps based on your app framework:
188185
dependencies: [
189186
.product(
190187
name: "PowerSync",
191-
package: "powersync-kotlin"
192-
),
193-
.product(
194-
name: "PowerSyncSqliteCore",
195-
package: "powersync-sqlite-core-swift"
196-
),
188+
package: "powersync-swift"
189+
)
197190
]
198191
)
199192
]
@@ -203,26 +196,15 @@ Please see the steps based on your app framework:
203196
2. Using Xcode:
204197

205198
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.
199+
2. When searching for the package use [https://github.com/powersync-ja/powersync-swift.git](https://github.com/powersync-ja/powersync-swift.git) as the URL and include the exact version e.g. `1.0.0-Beta.x` as shown below:
206200

207-
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:
208-
209-
<Frame>
210-
<img src="/images/swift.avif" />
211-
</Frame>
212-
213-
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:
214-
215-
<Frame>
216-
<img src="/images/image (1).png" />
217-
</Frame>
218-
219-
<Note>
220-
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).
221-
</Note>
201+
<Frame>
202+
<img src="/images/Swift-Xcode.png"></img>
203+
</Frame>
222204

223205
See the full SDK reference for further details and getting started instructions:
224206

225-
<Card title="Swift (Alpha)" icon="swift" href="/client-sdk-references/swift" horizontal />
207+
<Card title="Swift (Beta)" icon="swift" href="/client-sdk-references/swift" horizontal />
226208
</Accordion>
227209

228210
## Next Steps
@@ -235,4 +217,4 @@ For an overview of the client-side steps required to set up PowerSync in your ap
235217

236218
3. [Integrate with your Backend](/installation/client-side-setup/integrating-with-your-backend)
237219

238-
For a walkthrough with example implementations for your platform, see the *Getting Started* section of the corresponding SDK reference linked above.
220+
For a walkthrough with example implementations for your platform, see the *Getting Started* section of the corresponding SDK reference linked above.

integration-guides/supabase-+-powersync.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ git clone https://github.com/powersync-ja/powersync-kotlin.git
183183
```
184184

185185
```bash Swift
186-
git clone git@github.com:powersync-ja/powersync-kotlin-swift-demo.git
186+
git clone https://github.com/powersync-ja/powersync-swift.git
187187

188-
# Open the project in XCode and follow the README instructions.
188+
# Open the Demo directory in XCode and follow the README instructions.
189189
```
190190

191191
</CodeGroup>

intro/powersync-overview.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ PowerSync is also designed to be client-side stack agnostic, and currently has c
4747
</Card>
4848

4949
<Card title="Swift" icon="swift" href="/client-sdk-references/swift">
50-
Currently in an alpha release.
50+
Currently in a beta release.
5151
</Card>
5252
</CardGroup>
5353

@@ -159,4 +159,4 @@ Explore and learn from example implementations and common use cases with PowerSy
159159
<Card title="Philosophy" icon="flux-capacitor" href="/intro/powersync-philosophy">
160160
Learn about the philosophy behind PowerSync and why we built it.
161161
</Card>
162-
</CardGroup>
162+
</CardGroup>

migration-guides/mongodb-atlas.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ We are constantly adding additional PowerSync Client SDKs and some of them are u
7878

7979
| Flavor | Status | ETA |
8080
| ------------------------------------------------------------------- | ----------- | ---------------- |
81-
| [JavaScript/Web](/client-sdk-references/javascript-web) | Stable | N/A |
81+
| [JavaScript/Web](/client-sdk-references/javascript-web) | Stable | N/A |
8282
| [React Native](/client-sdk-references/react-native-and-expo) & Expo | Stable | N/A |
8383
| [Flutter/Dart](/client-sdk-references/flutter) | Stable | N/A |
8484
| [Kotlin Multiplatform](/client-sdk-references/kotlin-multiplatform) | Beta | V1 ETA 2025Q1 |
85-
| [Swift](/client-sdk-references/swift) | Alpha | Beta ETA 2024Q4 |
85+
| [Swift](/client-sdk-references/swift) | Beta | V1 ETA 2025Q1 |
8686
| Node.js | PoC | Alpha ETA 2024Q4 |
8787
| .NET | Not Started | Alpha ETA 2025Q1 |
8888

0 commit comments

Comments
 (0)