Skip to content

Commit 7c59a46

Browse files
added more sendable annotations. Update example app to use Swift 6 Strict concurrency checking
1 parent 4dbaedf commit 7c59a46

21 files changed

+174
-123
lines changed

Demo/PowerSyncExample.xcodeproj/project.pbxproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@
645645
SDKROOT = iphoneos;
646646
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
647647
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
648+
SWIFT_STRICT_CONCURRENCY = complete;
648649
};
649650
name = Debug;
650651
};
@@ -701,6 +702,7 @@
701702
OTHER_LDFLAGS = "-lsqlite3";
702703
SDKROOT = iphoneos;
703704
SWIFT_COMPILATION_MODE = wholemodule;
705+
SWIFT_STRICT_CONCURRENCY = complete;
704706
VALIDATE_PRODUCT = YES;
705707
};
706708
name = Release;
@@ -742,7 +744,7 @@
742744
SWIFT_OBJC_BRIDGING_HEADER = "PowerSyncExample/PowerSyncExample-Bridging-Header.h";
743745
"SWIFT_OBJC_BRIDGING_HEADER[arch=*]" = "";
744746
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
745-
SWIFT_VERSION = 5.0;
747+
SWIFT_VERSION = 6.0;
746748
TARGETED_DEVICE_FAMILY = "1,2";
747749
};
748750
name = Debug;
@@ -781,7 +783,7 @@
781783
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
782784
SWIFT_EMIT_LOC_STRINGS = YES;
783785
SWIFT_OBJC_BRIDGING_HEADER = "PowerSyncExample/PowerSyncExample-Bridging-Header.h";
784-
SWIFT_VERSION = 5.0;
786+
SWIFT_VERSION = 6.0;
785787
TARGETED_DEVICE_FAMILY = "1,2";
786788
};
787789
name = Release;

Demo/PowerSyncExample/Components/AddListView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ struct AddListView: View {
1313
Task {
1414
do {
1515
try await system.insertList(newList)
16-
await completion(.success(true))
16+
completion(.success(true))
1717
} catch {
18-
await completion(.failure(error))
18+
completion(.failure(error))
1919
throw error
2020
}
2121
}

Demo/PowerSyncExample/Components/AddTodoListView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ struct AddTodoListView: View {
1515
Task{
1616
do {
1717
try await system.insertTodo(newTodo, listId)
18-
await completion(.success(true))
18+
completion(.success(true))
1919
} catch {
20-
await completion(.failure(error))
20+
completion(.failure(error))
2121
throw error
2222
}
2323
}

Demo/PowerSyncExample/PowerSync/SupabaseConnector.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ private enum PostgresFatalCodes {
3838
}
3939

4040
@Observable
41+
@MainActor // _session is mutable, limiting to the MainActor satisfies Sendable constraints
4142
final class SupabaseConnector: PowerSyncBackendConnectorProtocol {
4243
let powerSyncEndpoint: String = Secrets.powerSyncEndpoint
4344
let client: SupabaseClient = .init(
4445
supabaseURL: Secrets.supabaseURL,
4546
supabaseKey: Secrets.supabaseAnonKey,
4647
)
47-
var session: Session?
48+
private(set) var session: Session?
4849
private var errorCode: String?
4950

5051
@ObservationIgnored

Demo/PowerSyncExample/PowerSync/SupabaseRemoteStorage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Foundation
22
import PowerSync
33
import Supabase
44

5-
class SupabaseRemoteStorage: RemoteStorageAdapter {
5+
final class SupabaseRemoteStorage: RemoteStorageAdapter {
66
let storage: Supabase.StorageFileApi
77

88
init(storage: Supabase.StorageFileApi) {

Demo/PowerSyncExample/PowerSync/SystemManager.swift

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@ func getAttachmentsDirectoryPath() throws -> String {
1313

1414
let logTag = "SystemManager"
1515

16+
/// We use the MainActor SupabaseConnector synchronously here, this requires specifying that SystemManager runs on the MainActor
17+
/// We don't actually block the MainActor with anything
1618
@Observable
17-
class SystemManager {
19+
@MainActor
20+
final class SystemManager {
1821
let connector = SupabaseConnector()
1922
let schema = AppSchema
2023
let db: PowerSyncDatabaseProtocol
2124

22-
var attachments: AttachmentQueue?
25+
let attachments: AttachmentQueue?
2326

2427
init() {
2528
db = PowerSyncDatabase(
@@ -226,25 +229,18 @@ class SystemManager {
226229
try await attachments.deleteFile(
227230
attachmentId: photoId
228231
) { transaction, _ in
229-
try self.deleteTodoInTX(
230-
id: todo.id,
231-
tx: transaction
232+
try transaction.execute(
233+
sql: "DELETE FROM \(TODOS_TABLE) WHERE id = ?",
234+
parameters: [todo.id]
232235
)
233236
}
234237
} else {
235-
try await db.writeTransaction { transaction in
236-
try self.deleteTodoInTX(
237-
id: todo.id,
238-
tx: transaction
238+
_ = try await db.writeTransaction { transaction in
239+
try transaction.execute(
240+
sql: "DELETE FROM \(TODOS_TABLE) WHERE id = ?",
241+
parameters: [todo.id]
239242
)
240243
}
241244
}
242245
}
243-
244-
private func deleteTodoInTX(id: String, tx: ConnectionContext) throws {
245-
_ = try tx.execute(
246-
sql: "DELETE FROM \(TODOS_TABLE) WHERE id = ?",
247-
parameters: [id]
248-
)
249-
}
250246
}

Sources/PowerSync/Kotlin/KotlinTypes.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ extension KotlinPowerSyncBackendConnector: @retroactive @unchecked Sendable {}
88
extension KotlinPowerSyncCredentials: @retroactive @unchecked Sendable {}
99
extension PowerSyncKotlin.KermitLogger: @retroactive @unchecked Sendable {}
1010
extension PowerSyncKotlin.SyncStatus: @retroactive @unchecked Sendable {}
11+
12+
extension PowerSyncKotlin.CrudEntry: @retroactive @unchecked Sendable {}
13+
extension PowerSyncKotlin.CrudBatch: @retroactive @unchecked Sendable {}
14+
extension PowerSyncKotlin.CrudTransaction: @retroactive @unchecked Sendable {}

Sources/PowerSync/Protocol/PowerSyncDatabaseProtocol.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Foundation
44
///
55
/// Provides options to customize network behavior and logging for PowerSync
66
/// HTTP requests and responses.
7-
public struct SyncClientConfiguration {
7+
public struct SyncClientConfiguration: Sendable {
88
/// Optional configuration for logging PowerSync HTTP requests.
99
///
1010
/// When provided, network requests will be logged according to the
@@ -23,7 +23,7 @@ public struct SyncClientConfiguration {
2323
/// Options for configuring a PowerSync connection.
2424
///
2525
/// Provides optional parameters to customize sync behavior such as throttling and retry policies.
26-
public struct ConnectOptions {
26+
public struct ConnectOptions: Sendable {
2727
/// Defaults to 1 second
2828
public static let DefaultCrudThrottle: TimeInterval = 1
2929

Sources/PowerSync/Protocol/Schema/Column.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Foundation
22
import PowerSyncKotlin
33

4-
public protocol ColumnProtocol: Equatable {
4+
public protocol ColumnProtocol: Equatable, Sendable {
55
/// Name of the column.
66
var name: String { get }
77
/// Type of the column.
@@ -15,7 +15,7 @@ public protocol ColumnProtocol: Equatable {
1515
var type: ColumnData { get }
1616
}
1717

18-
public enum ColumnData {
18+
public enum ColumnData: Sendable {
1919
case text
2020
case integer
2121
case real
@@ -25,23 +25,23 @@ public enum ColumnData {
2525
public struct Column: ColumnProtocol {
2626
public let name: String
2727
public let type: ColumnData
28-
28+
2929
public init(
3030
name: String,
3131
type: ColumnData
3232
) {
3333
self.name = name
3434
self.type = type
3535
}
36-
36+
3737
public static func text(_ name: String) -> Column {
3838
Column(name: name, type: .text)
3939
}
40-
40+
4141
public static func integer(_ name: String) -> Column {
4242
Column(name: name, type: .integer)
4343
}
44-
44+
4545
public static func real(_ name: String) -> Column {
4646
Column(name: name, type: .real)
4747
}

Sources/PowerSync/Protocol/Schema/Index.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Foundation
22
import PowerSyncKotlin
33

4-
public protocol IndexProtocol {
4+
public protocol IndexProtocol: Sendable {
55
///
66
/// Descriptive name of the index.
77
///
@@ -15,22 +15,22 @@ public protocol IndexProtocol {
1515
public struct Index: IndexProtocol {
1616
public let name: String
1717
public let columns: [IndexedColumnProtocol]
18-
18+
1919
public init(
2020
name: String,
2121
columns: [IndexedColumnProtocol]
2222
) {
2323
self.name = name
2424
self.columns = columns
2525
}
26-
26+
2727
public init(
2828
name: String,
2929
_ columns: IndexedColumnProtocol...
3030
) {
3131
self.init(name: name, columns: columns)
3232
}
33-
33+
3434
public static func ascending(
3535
name: String,
3636
columns: [String]
@@ -40,7 +40,7 @@ public struct Index: IndexProtocol {
4040
columns: columns.map { IndexedColumn.ascending($0) }
4141
)
4242
}
43-
43+
4444
public static func ascending(
4545
name: String,
4646
column: String

0 commit comments

Comments
 (0)