From cd84db38733d713a5e6e596b2cdde2e3ca8d16bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Tue, 9 Sep 2025 21:32:35 +0200 Subject: [PATCH 01/11] Xcode 26 upgrade --- .../DemoApps/GRDBDemo/GRDBDemo.xcodeproj/project.pbxproj | 4 +++- .../xcshareddata/xcschemes/GRDBDemo.xcscheme | 2 +- GRDB.xcodeproj/project.pbxproj | 7 ++++++- GRDB.xcodeproj/xcshareddata/xcschemes/GRDB.xcscheme | 2 +- GRDBCustom.xcodeproj/project.pbxproj | 7 ++++++- .../xcshareddata/xcschemes/GRDBCustom.xcscheme | 2 +- .../xcshareddata/xcschemes/GRDBProfiling.xcscheme | 2 +- 7 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Documentation/DemoApps/GRDBDemo/GRDBDemo.xcodeproj/project.pbxproj b/Documentation/DemoApps/GRDBDemo/GRDBDemo.xcodeproj/project.pbxproj index 47782e062..6edc31973 100644 --- a/Documentation/DemoApps/GRDBDemo/GRDBDemo.xcodeproj/project.pbxproj +++ b/Documentation/DemoApps/GRDBDemo/GRDBDemo.xcodeproj/project.pbxproj @@ -158,7 +158,7 @@ attributes = { BuildIndependentTargetsInParallel = 1; LastSwiftUpdateCheck = 1600; - LastUpgradeCheck = 1600; + LastUpgradeCheck = 2600; TargetAttributes = { 56CFC6432C9F1DC9000B5023 = { CreatedOnToolsVersion = 16.0; @@ -293,6 +293,7 @@ MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; + STRING_CATALOG_GENERATE_SYMBOLS = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -350,6 +351,7 @@ MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; SDKROOT = iphoneos; + STRING_CATALOG_GENERATE_SYMBOLS = YES; SWIFT_COMPILATION_MODE = wholemodule; SWIFT_EMIT_LOC_STRINGS = YES; VALIDATE_PRODUCT = YES; diff --git a/Documentation/DemoApps/GRDBDemo/GRDBDemo.xcodeproj/xcshareddata/xcschemes/GRDBDemo.xcscheme b/Documentation/DemoApps/GRDBDemo/GRDBDemo.xcodeproj/xcshareddata/xcschemes/GRDBDemo.xcscheme index 386a9790f..8946129d7 100644 --- a/Documentation/DemoApps/GRDBDemo/GRDBDemo.xcodeproj/xcshareddata/xcschemes/GRDBDemo.xcscheme +++ b/Documentation/DemoApps/GRDBDemo/GRDBDemo.xcodeproj/xcshareddata/xcschemes/GRDBDemo.xcscheme @@ -1,6 +1,6 @@ Date: Tue, 9 Sep 2025 21:58:23 +0200 Subject: [PATCH 02/11] Fix a compiler error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The error was: > use of ‘@import’ in framework header is discouraged, including this header requires -fmodules This commit applies the fix recommended at https://developer.apple.com/documentation/xcode/identifying-and-addressing-framework-module-issues --- SQLiteCustom/GRDB.h | 4 ++-- Support/GRDB.h | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/SQLiteCustom/GRDB.h b/SQLiteCustom/GRDB.h index 00a7454a7..af41eb628 100755 --- a/SQLiteCustom/GRDB.h +++ b/SQLiteCustom/GRDB.h @@ -1,4 +1,4 @@ -@import Foundation; +#import //! Project version number for GRDB. FOUNDATION_EXPORT double GRDB_VersionNumber; @@ -8,4 +8,4 @@ FOUNDATION_EXPORT const unsigned char GRDB_VersionString[]; #import #import -#import "GRDB-Bridging.h" +#import diff --git a/Support/GRDB.h b/Support/GRDB.h index 69ad6ed45..71687094c 100644 --- a/Support/GRDB.h +++ b/Support/GRDB.h @@ -1,4 +1,4 @@ -@import Foundation; +#import //! Project version number for GRDB. FOUNDATION_EXPORT double GRDB_VersionNumber; @@ -7,4 +7,3 @@ FOUNDATION_EXPORT double GRDB_VersionNumber; FOUNDATION_EXPORT const unsigned char GRDB_VersionString[]; #import - From fd7adf7fb3debdd31bf079f473fbc0d82b6914ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Tue, 9 Sep 2025 21:35:58 +0200 Subject: [PATCH 03/11] SendableMetatype for compiler >= 6.2 --- GRDB/Utils/Utils.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/GRDB/Utils/Utils.swift b/GRDB/Utils/Utils.swift index d690b9eec..dd7ce059f 100644 --- a/GRDB/Utils/Utils.swift +++ b/GRDB/Utils/Utils.swift @@ -23,6 +23,14 @@ public func databaseQuestionMarks(count: Int) -> String { repeatElement("?", count: count).joined(separator: ",") } +#if compiler(>=6.2) +/// A synonym for `SendableMetatype` in Swift 6.2, and `Any` otherwise. +public typealias GRDBSendableMetatype = SendableMetatype +#else +/// A synonym for `SendableMetatype` in Swift 6.2, and `Any` otherwise. +public typealias GRDBSendableMetatype = Any +#endif + // MARK: - Internal /// Reserved for GRDB: do not use. From cf1702630f4cfc9fa475b683c3477479e503750b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Tue, 9 Sep 2025 21:38:42 +0200 Subject: [PATCH 04/11] DatabaseAggregate is SendableMetatype DatabaseAggregate does not support isolated conformances: it must be able to aggregate values whenever a database access is performed. This can happen in a nonisolated fashion. --- GRDB/Core/DatabaseFunction.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GRDB/Core/DatabaseFunction.swift b/GRDB/Core/DatabaseFunction.swift index 223fded9b..f6e6a84de 100644 --- a/GRDB/Core/DatabaseFunction.swift +++ b/GRDB/Core/DatabaseFunction.swift @@ -492,7 +492,7 @@ public final class DatabaseFunction: Identifiable, Sendable { /// try Int.fetchOne(db, sql: "SELECT mysum(i) FROM test")! // 3 /// } /// ``` -public protocol DatabaseAggregate { +public protocol DatabaseAggregate: GRDBSendableMetatype { /// Creates an aggregate. /// /// A new instance is created for each aggregation. From f435715f7502975c3fc395d7bf59a5f3df7f60cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Tue, 9 Sep 2025 21:42:37 +0200 Subject: [PATCH 05/11] ValueReducer is SendableMetatype ValueReducer does not support isolated conformances: it must be able to reduce observed values when needed. This can happen in a nonisolated fashion. --- GRDB/ValueObservation/Reducers/ValueReducer.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GRDB/ValueObservation/Reducers/ValueReducer.swift b/GRDB/ValueObservation/Reducers/ValueReducer.swift index 8c7386693..44411cbfb 100644 --- a/GRDB/ValueObservation/Reducers/ValueReducer.swift +++ b/GRDB/ValueObservation/Reducers/ValueReducer.swift @@ -11,7 +11,7 @@ // which is its `Fetcher`. /// Implementation details of `ValueReducer`. -public protocol _ValueReducer { +public protocol _ValueReducer: GRDBSendableMetatype { /// The Sendable type that fetches database values associatedtype Fetcher: _ValueReducerFetcher From 79ce0ff5f35f03931c845a74b00d474c42fec871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Tue, 9 Sep 2025 22:02:53 +0200 Subject: [PATCH 06/11] Avoid a compiler warning --- GRDB/QueryInterface/Request/QueryInterfaceRequest.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift b/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift index 66816236b..c53cca1c0 100644 --- a/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift +++ b/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift @@ -362,11 +362,13 @@ extension QueryInterfaceRequest: SelectionRequest { public func selectID() -> QueryInterfaceRequest where RowDecoder: Identifiable { - selectWhenConnected { db in - let primaryKey = try db.primaryKey(self.databaseTableName) + let databaseTableName = self.databaseTableName + + return selectWhenConnected { db in + let primaryKey = try db.primaryKey(databaseTableName) GRDBPrecondition( primaryKey.columns.count == 1, - "selectID requires a single-column primary key in the table \(self.databaseTableName)") + "selectID requires a single-column primary key in the table \(databaseTableName)") return [Column(primaryKey.columns[0])] }.asRequest(of: RowDecoder.ID.self) } From f88c7202cda80336ab69fb0301840d04a53d4855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Tue, 9 Sep 2025 22:07:54 +0200 Subject: [PATCH 07/11] TableRecord is GRDBSendableMetatype This is required because the value of databaseSelection is not required to be Sendable. This forces TableRecord.relationForAll to postpone the definition of the selection until we access the database - in a nonisolated fashion. --- GRDB/Record/TableRecord.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GRDB/Record/TableRecord.swift b/GRDB/Record/TableRecord.swift index c3a98756b..716b4fc0b 100644 --- a/GRDB/Record/TableRecord.swift +++ b/GRDB/Record/TableRecord.swift @@ -134,7 +134,7 @@ import Foundation /// - ``select(_:as:)-tjh0`` /// - ``updateAll(_:onConflict:_:)-7vv9x`` /// - ``updateAll(_:onConflict:_:)-7atfw`` -public protocol TableRecord { +public protocol TableRecord: GRDBSendableMetatype { /// A type that defines columns. /// /// For example: From 32ed290a1b048352da42b27848c620a3bc0bc296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Tue, 9 Sep 2025 22:10:21 +0200 Subject: [PATCH 08/11] EncodableRecord is GRDBSendableMetatype This allows us to apply the encoding strategies for Data, Date, UUID when we know we need it, i.e. when we know the primary key, and this happens when we access the database - in a nonisolated fashion. --- GRDB/Record/EncodableRecord.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GRDB/Record/EncodableRecord.swift b/GRDB/Record/EncodableRecord.swift index 27f995370..98261bc94 100644 --- a/GRDB/Record/EncodableRecord.swift +++ b/GRDB/Record/EncodableRecord.swift @@ -39,7 +39,7 @@ import Foundation // For JSONEncoder /// - ``databaseChanges(from:)`` /// - ``databaseChanges(modify:)`` /// - ``databaseEquals(_:)`` -public protocol EncodableRecord { +public protocol EncodableRecord: GRDBSendableMetatype { /// Encodes the record into the provided persistence container. /// /// In your implementation of this method, store in the `container` argument From 1a3842e4bc6fd03144d0891e5b2ee6e7a0121965 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Tue, 9 Sep 2025 21:47:15 +0200 Subject: [PATCH 09/11] Combine and concurrency: lol --- GRDB/Core/DatabaseRegionObservation.swift | 8 ++++++-- GRDB/Utils/OnDemandFuture.swift | 6 ++++-- GRDB/ValueObservation/ValueObservation.swift | 8 ++++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/GRDB/Core/DatabaseRegionObservation.swift b/GRDB/Core/DatabaseRegionObservation.swift index ec6319721..246e3627a 100644 --- a/GRDB/Core/DatabaseRegionObservation.swift +++ b/GRDB/Core/DatabaseRegionObservation.swift @@ -201,7 +201,11 @@ extension DatabasePublishers { self.observation = observation } - public func receive(subscriber: S) where S: Subscriber, Failure == S.Failure, Output == S.Input { + public func receive(subscriber: S) + where S: Subscriber & GRDBSendableMetatype, + Failure == S.Failure, + Output == S.Input + { let subscription = DatabaseRegionSubscription( writer: writer, observation: observation, @@ -212,7 +216,7 @@ extension DatabasePublishers { private class DatabaseRegionSubscription: Subscription, @unchecked Sendable - where Downstream: Subscriber, + where Downstream: Subscriber & GRDBSendableMetatype, Downstream.Failure == Error, Downstream.Input == Database { diff --git a/GRDB/Utils/OnDemandFuture.swift b/GRDB/Utils/OnDemandFuture.swift index 938750d4a..b12840a1d 100644 --- a/GRDB/Utils/OnDemandFuture.swift +++ b/GRDB/Utils/OnDemandFuture.swift @@ -27,7 +27,7 @@ struct OnDemandFuture: Publisher { self.attemptToFulfill = attemptToFulfill } - func receive(subscriber: S) where S: Subscriber, Failure == S.Failure, Output == S.Input { + func receive(subscriber: S) where S: Subscriber & GRDBSendableMetatype, Failure == S.Failure, Output == S.Input { let subscription = OnDemandFutureSubscription( attemptToFulfill: attemptToFulfill, downstream: subscriber) @@ -35,7 +35,9 @@ struct OnDemandFuture: Publisher { } } -private class OnDemandFutureSubscription: Subscription, @unchecked Sendable { +private class OnDemandFutureSubscription: Subscription, @unchecked Sendable +where Downstream: Subscriber & GRDBSendableMetatype +{ // @unchecked because `state` is protected with `lock`. typealias Promise = @Sendable (Result) -> Void diff --git a/GRDB/ValueObservation/ValueObservation.swift b/GRDB/ValueObservation/ValueObservation.swift index 92cfe9864..642c2465b 100644 --- a/GRDB/ValueObservation/ValueObservation.swift +++ b/GRDB/ValueObservation/ValueObservation.swift @@ -511,7 +511,11 @@ extension DatabasePublishers { self.start = start } - public func receive(subscriber: S) where S: Subscriber, Failure == S.Failure, Output == S.Input { + public func receive(subscriber: S) + where S: Subscriber & GRDBSendableMetatype, + Failure == S.Failure, + Output == S.Input + { let subscription = ValueSubscription( start: start, downstream: subscriber) @@ -521,7 +525,7 @@ extension DatabasePublishers { private class ValueSubscription: Subscription, @unchecked Sendable - where Downstream: Subscriber, + where Downstream: Subscriber & GRDBSendableMetatype, Downstream.Failure == Error { // @unchecked Sendable because `cancellable` and `state` are From 7ec88b76e091cb3933535c8df4969367e0374ddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Tue, 9 Sep 2025 22:18:50 +0200 Subject: [PATCH 10/11] Start an immediate observation In the iOS 26 simulator the demo app would show a flash of missing content. --- .../DemoApps/GRDBDemo/GRDBDemo/Views/PlayerListModel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/DemoApps/GRDBDemo/GRDBDemo/Views/PlayerListModel.swift b/Documentation/DemoApps/GRDBDemo/GRDBDemo/Views/PlayerListModel.swift index 0ea0b85ef..2c1fa4909 100644 --- a/Documentation/DemoApps/GRDBDemo/GRDBDemo/Views/PlayerListModel.swift +++ b/Documentation/DemoApps/GRDBDemo/GRDBDemo/Views/PlayerListModel.swift @@ -56,7 +56,7 @@ import GRDB // Start observing the database. // Previous observation, if any, is cancelled. - cancellable = observation.start(in: appDatabase.reader) { error in + cancellable = observation.start(in: appDatabase.reader, scheduling: .immediate) { error in // Handle error } onChange: { [unowned self] players in self.players = players From 6a25b3538e2afaff413a4b0db2e6e14abb065415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Wed, 10 Sep 2025 07:41:42 +0200 Subject: [PATCH 11/11] DocC for GRDBSendableMetatype --- GRDB/Documentation.docc/SwiftConcurrency.md | 6 ++++++ GRDB/Utils/Utils.swift | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/GRDB/Documentation.docc/SwiftConcurrency.md b/GRDB/Documentation.docc/SwiftConcurrency.md index 4fcfc15fa..35ce83c57 100644 --- a/GRDB/Documentation.docc/SwiftConcurrency.md +++ b/GRDB/Documentation.docc/SwiftConcurrency.md @@ -229,5 +229,11 @@ Task { } ``` +## Topics + +### Supporting Types + +- ``GRDBSendableMetatype`` + [demo apps]: https://github.com/groue/GRDB.swift/tree/master/Documentation/DemoApps [Migrating to Swift 6]: https://www.swift.org/migration/documentation/migrationguide/ diff --git a/GRDB/Utils/Utils.swift b/GRDB/Utils/Utils.swift index dd7ce059f..47bb3a16c 100644 --- a/GRDB/Utils/Utils.swift +++ b/GRDB/Utils/Utils.swift @@ -24,10 +24,12 @@ public func databaseQuestionMarks(count: Int) -> String { } #if compiler(>=6.2) -/// A synonym for `SendableMetatype` in Swift 6.2, and `Any` otherwise. +/// A synonym for the standard `SendableMetatype` protocol in Swift 6.2, +/// and `Any` in previous compiler versions. public typealias GRDBSendableMetatype = SendableMetatype #else -/// A synonym for `SendableMetatype` in Swift 6.2, and `Any` otherwise. +/// A synonym for the standard `SendableMetatype` protocol in Swift 6.2, +/// and `Any` in previous compiler versions. public typealias GRDBSendableMetatype = Any #endif