Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client-sdk-references/introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ Select your client framework for the full SDK reference, getting started instruc
Currently in a beta release.
</Card>
<Card title="Swift" icon="swift" href="/client-sdk-references/swift">
Currently in an alpha release.
Currently in a beta release.
</Card>
</CardGroup>
6 changes: 5 additions & 1 deletion client-sdk-references/kotlin-multiplatform.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ sidebarTitle: Overview
<Card title="Source Code" icon="github" href="https://github.com/powersync-ja/powersync-kotlin/">
Refer to the powersync-kotlin repo on GitHub.
</Card>
<Card title="API Reference (Coming soon)" icon="book" href="https://powersync-ja.github.io/powersync-js/react-native-sdk">
<Card title="API Reference (Coming soon)" icon="book" href="">
A full API Reference for this SDK is not yet available. This is planned for the stable release.
</Card>
<Card title="Example Projects" icon="code" href="/resources/demo-apps-example-projects#kotlin-multiplatform">
Gallery of example projects/demo apps built with Kotlin Multiplatform and PowerSync.
</Card>
</CardGroup>

<Note>
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.
</Note>

### SDK Features

* Provides real-time streaming of database changes.
Expand Down
125 changes: 57 additions & 68 deletions client-sdk-references/swift.mdx
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
---
title: "Swift (Alpha)"
title: "Swift (Beta)"
sidebarTitle: "Overview"
---

<CardGroup cols={3}>
<Card title="Source Code" icon="github" href="https://github.com/powersync-ja/powersync-swift/">
Refer to the powersync-swift repo on GitHub.
</Card>
<Card title="API Reference (Coming soon)" icon="book" href="">
A full API Reference for this SDK is not yet available. This is planned for the stable release.
</Card>
<Card title="Example Projects" icon="code" href="/resources/demo-apps-example-projects#swift">
Gallery of example projects/demo apps built with PowerSync and Swift.
</Card>
</CardGroup>

<Note>
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.
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.
</Note>

## Kotlin Multiplatform -> Native Swift SDK

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).

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.
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.

<Tip>
**Demo App**

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.
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.
</Tip>

### SDK Features
Expand All @@ -43,11 +53,9 @@ let package = Package(
dependencies: [
...
.package(
url: "https://github.com/powersync-ja/powersync-kotlin",
exact: "1.0.0-BETA5.0"
),
.package(
url: "https://github.com/powersync-ja/powersync-sqlite-core-swift",
url: "https://github.com/powersync-ja/powersync-swift",
// Exact version required while still in beta
exact: "<version>"
),
],
targets: [
Expand All @@ -56,11 +64,7 @@ let package = Package(
dependencies: [
.product(
name: "PowerSync",
package: "powersync-kotlin"
),
.product(
name: "PowerSyncSqliteCore",
package: "powersync-sqlite-core-swift"
package: "powersync-swift"
),
]
)
Expand All @@ -71,21 +75,22 @@ let package = Package(
2. Using Xcode:

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.
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:
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:

<Frame>

<img src="/images/swift.avif"></img>
<img src="/images/Swift-Xcode.png"></img>
</Frame>

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

<Note>
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).
</Note>
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:
* The `PowerSyncDatabase` no longer needs a driver argument and it must be removed.
* The interface for `PowerSyncDatabase` now uses `PowerSyncDatabaseProtocol` which may require some changes to databases uses.
* If you were using `__uploadData` and `__fetchCredentials` in your `PowerSyncBackendConnector` you must remove the `__` and update the methods to `uploadData` and `fetchCredentials`.
* `@MainThread` usage is no longer required and should be removed.
* Implementing `SuspendTaskWrapper` for database transactions is no longer required and should be removed.

See the [Todo List Demo app](https://github.com/powersync-ja/powersync-swift/tree/main/Demo) as a reference.

## Getting Started

Expand Down Expand Up @@ -116,44 +121,37 @@ let lists = Table(
name: LISTS_TABLE,
columns: [
// ID column is automatically included
Column(name: "name", type: ColumnType.text),
Column(name: "created_at", type: ColumnType.text),
Column(name: "owner_id", type: ColumnType.text)
],
indexes: [],
localOnly: false,
insertOnly: false,
viewNameOverride: LISTS_TABLE
.text("name"),
.text("created_at"),
.text("owner_id")
]
)

let todos = Table(
name: TODOS_TABLE,
// ID column is automatically included
columns: [
Column(name: "list_id", type: ColumnType.text),
Column(name: "photo_id", type: ColumnType.text),
Column(name: "description", type: ColumnType.text),
.text("list_id"),
.text("photo_id"),
.text("description"),
// 0 or 1 to represent false or true
Column(name: "completed", type: ColumnType.integer),
Column(name: "created_at", type: ColumnType.text),
Column(name: "completed_at", type: ColumnType.text),
Column(name: "created_by", type: ColumnType.text),
Column(name: "completed_by", type: ColumnType.text)
.integer("completed"),
.text("created_at"),
.text("completed_at"),
.text("created_by"),
.text("completed_by")
],
indexes: [
Index(
name: "list_id",
columns: [
IndexedColumn(column: "list_id", ascending: true, columnDefinition: nil, type: nil)
IndexedColumn.ascending("list_id")
]
)
],
localOnly: false,
insertOnly: false,
viewNameOverride: TODOS_TABLE
]
)

let AppSchema = Schema(tables: [lists, todos])
let AppSchema = Schema(lists, todos)
```

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

```swift
// Comes from the PowerSync package
let factory = DatabaseDriverFactory()
// Comes from the AppSchema defined above
let schema = AppSchema
var db = PowerSyncDatabase(
factory: factory,
let db = PowerSyncDatabase(
schema: schema,
dbFilename: "powersync-swift.sqlite",
params: [:]
dbFilename: "powersync-swift.sqlite"
)
```

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

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

return {
endpoint: '[Your PowerSync instance URL or self-hosted endpoint]',
Expand All @@ -218,7 +211,7 @@ class MyConnector: PowerSyncBackendConnector {
}
}

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

```

<Info>
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.
</Info>

## Using PowerSync: CRUD functions

Once the PowerSync instance is configured you can start using the SQLite DB functions.
Expand Down Expand Up @@ -311,7 +300,7 @@ func watchLists(_ callback: @escaping (_ lists: [ListContent]) -> Void ) async {
)
}
) {
callback(lists as! [ListContent])
callback(lists)
}
}
```
Expand All @@ -336,12 +325,12 @@ func updateTodo(_ todo: Todo) async throws {
}

func deleteTodo(id: String) async throws {
try await db.writeTransaction(callback: SuspendTaskWrapper {
try await db.execute(
sql: "DELETE FROM \(TODOS_TABLE) WHERE id = ?",
parameters: [id]
)
try await db.writeTransaction(callback: { transaction in
_ = try await transaction.execute(
sql: "DELETE FROM \(TODOS_TABLE) WHERE id = ?",
parameters: [id]
)
return
})
}
```
```
Binary file added images/Swift-Xcode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/image (1).png
Binary file not shown.
Binary file removed images/swift.avif
Binary file not shown.
40 changes: 11 additions & 29 deletions installation/client-side-setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The next step after configuring your database and connecting it to your PowerSyn

2. Write mutations to your backend

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).
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).

Please see the steps based on your app framework:

Expand Down Expand Up @@ -175,11 +175,8 @@ Please see the steps based on your app framework:
dependencies: [
...
.package(
url: "https://github.com/powersync-ja/powersync-kotlin",
exact: "1.0.0-BETA5.0"
),
.package(
url: "https://github.com/powersync-ja/powersync-sqlite-core-swift",
url: "https://github.com/powersync-ja/powersync-swift",
exact: "<version>"
),
],
targets: [
Expand All @@ -188,12 +185,8 @@ Please see the steps based on your app framework:
dependencies: [
.product(
name: "PowerSync",
package: "powersync-kotlin"
),
.product(
name: "PowerSyncSqliteCore",
package: "powersync-sqlite-core-swift"
),
package: "powersync-swift"
)
]
)
]
Expand All @@ -203,26 +196,15 @@ Please see the steps based on your app framework:
2. Using Xcode:

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.
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:

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:

<Frame>
<img src="/images/swift.avif" />
</Frame>

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:

<Frame>
<img src="/images/image (1).png" />
</Frame>

<Note>
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).
</Note>
<Frame>
<img src="/images/Swift-Xcode.png"></img>
</Frame>

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

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

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

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

For a walkthrough with example implementations for your platform, see the *Getting Started* section of the corresponding SDK reference linked above.
For a walkthrough with example implementations for your platform, see the *Getting Started* section of the corresponding SDK reference linked above.
4 changes: 2 additions & 2 deletions integration-guides/supabase-+-powersync.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ git clone https://github.com/powersync-ja/powersync-kotlin.git
```

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

# Open the project in XCode and follow the README instructions.
# Open the Demo directory in XCode and follow the README instructions.
```

</CodeGroup>
Expand Down
4 changes: 2 additions & 2 deletions intro/powersync-overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ PowerSync is also designed to be client-side stack agnostic, and currently has c
</Card>

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

Expand Down Expand Up @@ -159,4 +159,4 @@ Explore and learn from example implementations and common use cases with PowerSy
<Card title="Philosophy" icon="flux-capacitor" href="/intro/powersync-philosophy">
Learn about the philosophy behind PowerSync and why we built it.
</Card>
</CardGroup>
</CardGroup>
4 changes: 2 additions & 2 deletions migration-guides/mongodb-atlas.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ We are constantly adding additional PowerSync Client SDKs and some of them are u

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

Expand Down
Loading
Loading