Skip to content

Commit 872a269

Browse files
Support Swift 6 Strict Concurrency Checking (#70)
1 parent f015d7e commit 872a269

39 files changed

+884
-782
lines changed

.github/workflows/build_and_test.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,20 @@ jobs:
1919
xcodebuild test -scheme PowerSync -destination "platform=iOS Simulator,name=iPhone 16"
2020
xcodebuild test -scheme PowerSync -destination "platform=macOS,arch=arm64,name=My Mac"
2121
xcodebuild test -scheme PowerSync -destination "platform=watchOS Simulator,arch=arm64,name=Apple Watch Ultra 2 (49mm)"
22+
23+
buildSwift6:
24+
name: Build and test with Swift 6
25+
runs-on: macos-latest
26+
steps:
27+
- uses: actions/checkout@v4
28+
- name: Set up XCode
29+
uses: maxim-lobanov/setup-xcode@v1
30+
with:
31+
xcode-version: latest-stable
32+
- name: Use Swift 6
33+
run: |
34+
sed -i '' 's|^// swift-tools-version:.*$|// swift-tools-version:6.1|' Package.swift
35+
- name: Build and Test
36+
run: |
37+
swift build -Xswiftc -strict-concurrency=complete
38+
swift test -Xswiftc -strict-concurrency=complete

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ DerivedData/
6969
.swiftpm/configuration/registries.json
7070
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
7171
.netrc
72-
72+
.vscode
73+
.sourcekit-lsp
7374

7475
Secrets.swift

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
## Unreleased
44

55
* Fix null values in CRUD entries being reported as strings.
6+
* Added support for Swift 6 strict concurrency checking.
7+
- Accepted query parameter types have been updated from `[Any]` to `[Sendable]`. This should cover all supported query parameter types.
8+
- Query and lock methods' return `Result` generic types now should extend `Sendable`.
9+
- Deprecated default `open class PowerSyncBackendConnector`. Devs should preferably implement the `PowerSyncBackendConnectorProtocol`
10+
11+
* *Potential Breaking Change*: Attachment helpers have been updated to better support Swift 6 strict concurrency checking. `Actor` isolation is improved, but developers who customize or extend `AttachmentQueue` will need to update their implementations. The default instantiation of `AttachmentQueue` remains unchanged.
12+
`AttachmentQueueProtocol` now defines the basic requirements for an attachment queue, with most base functionality provided via an extension. Custom implementations should extend `AttachmentQueueProtocol`.
613
* [Internal] Instantiate Kotlin Kermit logger directly.
714
* [Internal] Improved connection context error handling.
815

Demo/PowerSyncExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Demo/PowerSyncExample/PowerSync/SupabaseConnector.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private enum PostgresFatalCodes {
3838
}
3939

4040
@Observable
41-
class SupabaseConnector: PowerSyncBackendConnector {
41+
final class SupabaseConnector: PowerSyncBackendConnectorProtocol {
4242
let powerSyncEndpoint: String = Secrets.powerSyncEndpoint
4343
let client: SupabaseClient = .init(
4444
supabaseURL: Secrets.supabaseURL,
@@ -50,8 +50,7 @@ class SupabaseConnector: PowerSyncBackendConnector {
5050
@ObservationIgnored
5151
private var observeAuthStateChangesTask: Task<Void, Error>?
5252

53-
override init() {
54-
super.init()
53+
init() {
5554
session = client.auth.currentSession
5655
observeAuthStateChangesTask = Task { [weak self] in
5756
guard let self = self else { return }
@@ -80,7 +79,7 @@ class SupabaseConnector: PowerSyncBackendConnector {
8079
return client.storage.from(bucket)
8180
}
8281

83-
override func fetchCredentials() async throws -> PowerSyncCredentials? {
82+
func fetchCredentials() async throws -> PowerSyncCredentials? {
8483
session = try await client.auth.session
8584

8685
if session == nil {
@@ -92,7 +91,7 @@ class SupabaseConnector: PowerSyncBackendConnector {
9291
return PowerSyncCredentials(endpoint: powerSyncEndpoint, token: token)
9392
}
9493

95-
override func uploadData(database: PowerSyncDatabaseProtocol) async throws {
94+
func uploadData(database: PowerSyncDatabaseProtocol) async throws {
9695
guard let transaction = try await database.getNextCrudTransaction() else { return }
9796

9897
var lastEntry: CrudEntry?

Demo/PowerSyncExample/PowerSync/SystemManager.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,17 +225,17 @@ class SystemManager {
225225
if let attachments, let photoId = todo.photoId {
226226
try await attachments.deleteFile(
227227
attachmentId: photoId
228-
) { tx, _ in
228+
) { transaction, _ in
229229
try self.deleteTodoInTX(
230230
id: todo.id,
231-
tx: tx
231+
tx: transaction
232232
)
233233
}
234234
} else {
235-
try await db.writeTransaction { tx in
235+
try await db.writeTransaction { transaction in
236236
try self.deleteTodoInTX(
237237
id: todo.id,
238-
tx: tx
238+
tx: transaction
239239
)
240240
}
241241
}

Sources/PowerSync/Kotlin/DatabaseLogger.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ import PowerSyncKotlin
66
private class KermitLogWriterAdapter: Kermit_coreLogWriter {
77
/// The underlying Swift log writer to forward log messages to.
88
let logger: any LoggerProtocol
9-
9+
1010
/// Initializes a new adapter.
1111
///
1212
/// - Parameter logger: A Swift log writer that will handle log output.
1313
init(logger: any LoggerProtocol) {
1414
self.logger = logger
1515
super.init()
1616
}
17-
17+
1818
/// Called by Kermit to log a message.
1919
///
2020
/// - Parameters:
2121
/// - severity: The severity level of the log.
2222
/// - message: The content of the log message.
2323
/// - tag: A string categorizing the log.
2424
/// - throwable: An optional Kotlin exception (ignored here).
25-
override func log(severity: Kermit_coreSeverity, message: String, tag: String, throwable: KotlinThrowable?) {
25+
override func log(severity: Kermit_coreSeverity, message: String, tag: String, throwable _: KotlinThrowable?) {
2626
switch severity {
2727
case PowerSyncKotlin.Kermit_coreSeverity.verbose:
2828
return logger.debug(message, tag: tag)
@@ -43,7 +43,7 @@ private class KermitLogWriterAdapter: Kermit_coreLogWriter {
4343
class KotlinKermitLoggerConfig: PowerSyncKotlin.Kermit_coreLoggerConfig {
4444
var logWriterList: [Kermit_coreLogWriter]
4545
var minSeverity: PowerSyncKotlin.Kermit_coreSeverity
46-
46+
4747
init(logWriterList: [Kermit_coreLogWriter], minSeverity: PowerSyncKotlin.Kermit_coreSeverity) {
4848
self.logWriterList = logWriterList
4949
self.minSeverity = minSeverity
@@ -54,46 +54,46 @@ class KotlinKermitLoggerConfig: PowerSyncKotlin.Kermit_coreLoggerConfig {
5454
///
5555
/// This class bridges Swift log writers with the Kotlin logging system and supports
5656
/// runtime configuration of severity levels and writer lists.
57-
class DatabaseLogger: LoggerProtocol {
57+
final class DatabaseLogger: LoggerProtocol {
5858
/// The underlying Kermit logger instance provided by the PowerSyncKotlin SDK.
5959
public let kLogger: PowerSyncKotlin.KermitLogger
6060
public let logger: any LoggerProtocol
61-
61+
6262
/// Initializes a new logger with an optional list of writers.
6363
///
6464
/// - Parameter logger: A logger which will be called for each internal log operation
6565
init(_ logger: any LoggerProtocol) {
6666
self.logger = logger
6767
// Set to the lowest severity. The provided logger should filter by severity
68-
self.kLogger = PowerSyncKotlin.KermitLogger(
68+
kLogger = PowerSyncKotlin.KermitLogger(
6969
config: KotlinKermitLoggerConfig(
7070
logWriterList: [KermitLogWriterAdapter(logger: logger)],
7171
minSeverity: Kermit_coreSeverity.verbose
7272
),
7373
tag: "PowerSync"
7474
)
7575
}
76-
76+
7777
/// Logs a debug-level message.
7878
public func debug(_ message: String, tag: String?) {
7979
logger.debug(message, tag: tag)
8080
}
81-
81+
8282
/// Logs an info-level message.
8383
public func info(_ message: String, tag: String?) {
8484
logger.info(message, tag: tag)
8585
}
86-
86+
8787
/// Logs a warning-level message.
8888
public func warning(_ message: String, tag: String?) {
8989
logger.warning(message, tag: tag)
9090
}
91-
91+
9292
/// Logs an error-level message.
9393
public func error(_ message: String, tag: String?) {
9494
logger.error(message, tag: tag)
9595
}
96-
96+
9797
/// Logs a fault (assert-level) message, typically used for critical issues.
9898
public func fault(_ message: String, tag: String?) {
9999
logger.fault(message, tag: tag)

0 commit comments

Comments
 (0)