From fc10db84fe42e7e910ab2944c126f9c8374e260f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Thu, 2 Nov 2023 16:26:57 +0100 Subject: [PATCH] Enable upcoming feature ExistentialAny in Swift 5.9 --- .../GRDBAsyncDemo/PlayerRequest.swift | 2 +- .../GRDBCombineDemo/PlayerRequest.swift | 2 +- GRDB/Core/Database.swift | 6 +- GRDB/Core/DatabaseError.swift | 2 +- GRDB/Core/DatabaseFunction.swift | 2 +- GRDB/Core/DatabasePool.swift | 16 ++-- GRDB/Core/DatabaseQueue.swift | 10 +-- GRDB/Core/DatabaseReader.swift | 16 ++-- GRDB/Core/DatabaseRegionObservation.swift | 8 +- GRDB/Core/DatabaseSnapshot.swift | 4 +- GRDB/Core/DatabaseSnapshotPool.swift | 2 +- GRDB/Core/DatabaseWriter.swift | 22 ++--- .../Foundation/DatabaseDateComponents.swift | 4 +- .../DatabaseValueConvertible+Decodable.swift | 4 +- .../DatabaseValueConvertible+Encodable.swift | 4 +- .../StandardLibrary/JSONRequiredEncoder.swift | 14 ++-- GRDB/Core/TransactionObserver.swift | 2 +- GRDB/Fixits.swift | 2 +- GRDB/Migration/DatabaseMigrator.swift | 6 +- .../Schema/Database+SchemaDefinition.swift | 2 +- GRDB/Record/EncodableRecord+Encodable.swift | 14 ++-- GRDB/Record/FetchableRecord+Decodable.swift | 38 ++++----- GRDB/Record/FetchableRecord.swift | 2 +- GRDB/Utils/Pool.swift | 2 +- GRDB/Utils/ReceiveValuesOn.swift | 4 +- GRDB/Utils/Utils.swift | 2 +- .../Observers/ValueConcurrentObserver.swift | 4 +- .../Observers/ValueWriteOnlyObserver.swift | 2 +- .../SharedValueObservation.swift | 10 +-- GRDB/ValueObservation/ValueObservation.swift | 18 ++--- Package.swift | 6 +- Package@swift-5.9.swift | 80 +++++++++++++++++++ Tests/CombineExpectations/Recorder.swift | 4 +- ...abaseRegionObservationPublisherTests.swift | 2 +- .../DatabaseWriterWritePublisherTests.swift | 2 +- .../ValueObservationPublisherTests.swift | 14 ++-- ...ciationPrefetchingCodableRecordTests.swift | 4 +- .../DatabasePoolConcurrencyTests.swift | 6 +- ...tabaseValueConvertibleDecodableTests.swift | 18 ++--- ...tabaseValueConvertibleEncodableTests.swift | 24 +++--- .../FetchableRecordDecodableTests.swift | 22 ++--- Tests/GRDBTests/InflectionsTests.swift | 2 +- ...tablePersistableRecordEncodableTests.swift | 22 ++--- .../SharedValueObservationTests.swift | 4 +- .../GRDBTests/TransactionObserverTests.swift | 2 +- .../GRDBTests/ValueObservationRecorder.swift | 10 +-- Tests/GRDBTests/ValueObservationTests.swift | 4 +- 47 files changed, 264 insertions(+), 188 deletions(-) create mode 100644 Package@swift-5.9.swift diff --git a/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/PlayerRequest.swift b/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/PlayerRequest.swift index 8c70aab8d..e0cef0acd 100644 --- a/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/PlayerRequest.swift +++ b/Documentation/DemoApps/GRDBAsyncDemo/GRDBAsyncDemo/PlayerRequest.swift @@ -27,7 +27,7 @@ struct PlayerRequest: Queryable { static var defaultValue: [Player] { [] } - func publisher(in appDatabase: AppDatabase) -> AnyPublisher<[Player], Error> { + func publisher(in appDatabase: AppDatabase) -> AnyPublisher<[Player], any Error> { // Build the publisher from the general-purpose read-only access // granted by `appDatabase.reader`. // Some apps will prefer to call a dedicated method of `appDatabase`. diff --git a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/PlayerRequest.swift b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/PlayerRequest.swift index 8c70aab8d..e0cef0acd 100644 --- a/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/PlayerRequest.swift +++ b/Documentation/DemoApps/GRDBCombineDemo/GRDBCombineDemo/PlayerRequest.swift @@ -27,7 +27,7 @@ struct PlayerRequest: Queryable { static var defaultValue: [Player] { [] } - func publisher(in appDatabase: AppDatabase) -> AnyPublisher<[Player], Error> { + func publisher(in appDatabase: AppDatabase) -> AnyPublisher<[Player], any Error> { // Build the publisher from the general-purpose read-only access // granted by `appDatabase.reader`. // Some apps will prefer to call a dedicated method of `appDatabase`. diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift index 982671172..509818929 100644 --- a/GRDB/Core/Database.swift +++ b/GRDB/Core/Database.swift @@ -308,7 +308,7 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib /// /// Invariant: `transactionDateResult` is nil iff connection is not /// inside a transaction. - var transactionDateResult: Result? + var transactionDateResult: Result? /// The date of the current transaction. /// @@ -1209,7 +1209,7 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib // Now that transaction has begun, we'll rollback in case of error. // But we'll throw the first caught error, so that user knows // what happened. - var firstError: Error? = nil + var firstError: (any Error)? = nil let needsRollback: Bool do { let completion = try operations() @@ -1353,7 +1353,7 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib // Now that savepoint has begun, we'll rollback in case of error. // But we'll throw the first caught error, so that user knows // what happened. - var firstError: Error? = nil + var firstError: (any Error)? = nil let needsRollback: Bool do { let completion = try operations() diff --git a/GRDB/Core/DatabaseError.swift b/GRDB/Core/DatabaseError.swift index 5695eb12b..ffb92b1df 100644 --- a/GRDB/Core/DatabaseError.swift +++ b/GRDB/Core/DatabaseError.swift @@ -186,7 +186,7 @@ extension ResultCode { /// // any other database error /// } /// ``` - public static func ~= (lhs: Self, rhs: Error) -> Bool { + public static func ~= (lhs: Self, rhs: any Error) -> Bool { guard let error = rhs as? DatabaseError else { return false } return lhs ~= error.extendedResultCode } diff --git a/GRDB/Core/DatabaseFunction.swift b/GRDB/Core/DatabaseFunction.swift index 81fe82574..3fe9abc6b 100644 --- a/GRDB/Core/DatabaseFunction.swift +++ b/GRDB/Core/DatabaseFunction.swift @@ -403,7 +403,7 @@ public final class DatabaseFunction: Hashable { } } - private static func report(error: Error, in sqliteContext: OpaquePointer?) { + private static func report(error: some Error, in sqliteContext: OpaquePointer?) { if let error = error as? DatabaseError { if let message = error.message { sqlite3_result_error(sqliteContext, message, -1) diff --git a/GRDB/Core/DatabasePool.swift b/GRDB/Core/DatabasePool.swift index 7dd0525fc..c7786861b 100644 --- a/GRDB/Core/DatabasePool.swift +++ b/GRDB/Core/DatabasePool.swift @@ -14,7 +14,7 @@ public final class DatabasePool { @LockedBox var databaseSnapshotCount = 0 /// If Database Suspension is enabled, this array contains the necessary `NotificationCenter` observers. - private var suspensionObservers: [NSObjectProtocol] = [] + private var suspensionObservers: [any NSObjectProtocol] = [] // MARK: - Database Information @@ -357,7 +357,7 @@ extension DatabasePool: DatabaseReader { } } - public func asyncRead(_ value: @escaping (Result) -> Void) { + public func asyncRead(_ value: @escaping (Result) -> Void) { guard let readerPool else { value(.failure(DatabaseError.connectionIsClosed())) return @@ -401,7 +401,7 @@ extension DatabasePool: DatabaseReader { } } - public func asyncUnsafeRead(_ value: @escaping (Result) -> Void) { + public func asyncUnsafeRead(_ value: @escaping (Result) -> Void) { guard let readerPool else { value(.failure(DatabaseError.connectionIsClosed())) return @@ -449,7 +449,7 @@ extension DatabasePool: DatabaseReader { public func concurrentRead(_ value: @escaping (Database) throws -> T) -> DatabaseFuture { // The semaphore that blocks until futureResult is defined: let futureSemaphore = DispatchSemaphore(value: 0) - var futureResult: Result? = nil + var futureResult: Result? = nil asyncConcurrentRead { dbResult in // Fetch and release the future @@ -464,7 +464,7 @@ extension DatabasePool: DatabaseReader { } } - public func spawnConcurrentRead(_ value: @escaping (Result) -> Void) { + public func spawnConcurrentRead(_ value: @escaping (Result) -> Void) { asyncConcurrentRead(value) } @@ -505,7 +505,7 @@ extension DatabasePool: DatabaseReader { /// ``` /// /// - parameter value: A function that accesses the database. - public func asyncConcurrentRead(_ value: @escaping (Result) -> Void) { + public func asyncConcurrentRead(_ value: @escaping (Result) -> Void) { // Check that we're on the writer queue... writer.execute { db in // ... and that no transaction is opened. @@ -665,7 +665,7 @@ extension DatabasePool: DatabaseReader { /// /// - important: The `completion` argument is executed in a serial /// dispatch queue, so make sure you use the transaction asynchronously. - func asyncWALSnapshotTransaction(_ completion: @escaping (Result) -> Void) { + func asyncWALSnapshotTransaction(_ completion: @escaping (Result) -> Void) { guard let readerPool else { completion(.failure(DatabaseError.connectionIsClosed())) return @@ -756,7 +756,7 @@ extension DatabasePool: DatabaseWriter { } } - public func asyncBarrierWriteWithoutTransaction(_ updates: @escaping (Result) -> Void) { + public func asyncBarrierWriteWithoutTransaction(_ updates: @escaping (Result) -> Void) { guard let readerPool else { updates(.failure(DatabaseError.connectionIsClosed())) return diff --git a/GRDB/Core/DatabaseQueue.swift b/GRDB/Core/DatabaseQueue.swift index ae763f694..65b200177 100644 --- a/GRDB/Core/DatabaseQueue.swift +++ b/GRDB/Core/DatabaseQueue.swift @@ -8,7 +8,7 @@ public final class DatabaseQueue { private let writer: SerializedDatabase /// If Database Suspension is enabled, this array contains the necessary `NotificationCenter` observers. - private var suspensionObservers: [NSObjectProtocol] = [] + private var suspensionObservers: [any NSObjectProtocol] = [] // MARK: - Configuration @@ -233,7 +233,7 @@ extension DatabaseQueue: DatabaseReader { } } - public func asyncRead(_ value: @escaping (Result) -> Void) { + public func asyncRead(_ value: @escaping (Result) -> Void) { writer.async { db in defer { // Ignore error because we can not notify it. @@ -258,7 +258,7 @@ extension DatabaseQueue: DatabaseReader { try writer.sync(value) } - public func asyncUnsafeRead(_ value: @escaping (Result) -> Void) { + public func asyncUnsafeRead(_ value: @escaping (Result) -> Void) { writer.async { value(.success($0)) } } @@ -279,7 +279,7 @@ extension DatabaseQueue: DatabaseReader { }) } - public func spawnConcurrentRead(_ value: @escaping (Result) -> Void) { + public func spawnConcurrentRead(_ value: @escaping (Result) -> Void) { // Check that we're on the writer queue... writer.execute { db in // ... and that no transaction is opened. @@ -379,7 +379,7 @@ extension DatabaseQueue: DatabaseWriter { try writer.sync(updates) } - public func asyncBarrierWriteWithoutTransaction(_ updates: @escaping (Result) -> Void) { + public func asyncBarrierWriteWithoutTransaction(_ updates: @escaping (Result) -> Void) { writer.async { updates(.success($0)) } } diff --git a/GRDB/Core/DatabaseReader.swift b/GRDB/Core/DatabaseReader.swift index a07abf9ec..3706b2d4d 100644 --- a/GRDB/Core/DatabaseReader.swift +++ b/GRDB/Core/DatabaseReader.swift @@ -213,7 +213,7 @@ public protocol DatabaseReader: AnyObject, Sendable { /// - parameter value: A closure which accesses the database. Its argument /// is a `Result` that provides the database connection, or the failure /// that would prevent establishing the read access to the database. - func asyncRead(_ value: @escaping (Result) -> Void) + func asyncRead(_ value: @escaping (Result) -> Void) /// Executes database operations, and returns their result after they have /// finished executing. @@ -284,7 +284,7 @@ public protocol DatabaseReader: AnyObject, Sendable { /// - parameter value: A closure which accesses the database. Its argument /// is a `Result` that provides the database connection, or the failure /// that would prevent establishing the read access to the database. - func asyncUnsafeRead(_ value: @escaping (Result) -> Void) + func asyncUnsafeRead(_ value: @escaping (Result) -> Void) /// Executes database operations, and returns their result after they have /// finished executing. @@ -575,9 +575,9 @@ extension DatabasePublishers { /// You build such a publisher from ``DatabaseReader``. public struct Read: Publisher { public typealias Output = Output - public typealias Failure = Error + public typealias Failure = any Error - fileprivate let upstream: AnyPublisher + fileprivate let upstream: AnyPublisher public func receive(subscriber: S) where S: Subscriber, Self.Failure == S.Failure, Self.Output == S.Input { upstream.receive(subscriber: subscriber) @@ -586,7 +586,7 @@ extension DatabasePublishers { } @available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) -extension Publisher where Failure == Error { +extension Publisher where Failure == any Error { fileprivate func eraseToReadPublisher() -> DatabasePublishers.Read { .init(upstream: eraseToAnyPublisher()) } @@ -677,7 +677,7 @@ extension AnyDatabaseReader: DatabaseReader { try base.read(value) } - public func asyncRead(_ value: @escaping (Result) -> Void) { + public func asyncRead(_ value: @escaping (Result) -> Void) { base.asyncRead(value) } @@ -686,7 +686,7 @@ extension AnyDatabaseReader: DatabaseReader { try base.unsafeRead(value) } - public func asyncUnsafeRead(_ value: @escaping (Result) -> Void) { + public func asyncUnsafeRead(_ value: @escaping (Result) -> Void) { base.asyncUnsafeRead(value) } @@ -757,7 +757,7 @@ extension DatabaseSnapshotReader { } // There is no such thing as an unsafe access to a snapshot. - public func asyncUnsafeRead(_ value: @escaping (Result) -> Void) { + public func asyncUnsafeRead(_ value: @escaping (Result) -> Void) { asyncRead(value) } } diff --git a/GRDB/Core/DatabaseRegionObservation.swift b/GRDB/Core/DatabaseRegionObservation.swift index a831e063b..06d3e8507 100644 --- a/GRDB/Core/DatabaseRegionObservation.swift +++ b/GRDB/Core/DatabaseRegionObservation.swift @@ -85,7 +85,7 @@ extension DatabaseRegionObservation { /// - returns: A DatabaseCancellable that can stop the observation. public func start( in writer: some DatabaseWriter, - onError: @escaping (Error) -> Void, + onError: @escaping (any Error) -> Void, onChange: @escaping (Database) -> Void) -> AnyDatabaseCancellable { @@ -188,7 +188,7 @@ extension DatabasePublishers { /// You build such a publisher from ``DatabaseRegionObservation``. public struct DatabaseRegion: Publisher { public typealias Output = Database - public typealias Failure = Error + public typealias Failure = any Error let writer: any DatabaseWriter let observation: DatabaseRegionObservation @@ -208,7 +208,7 @@ extension DatabasePublishers { } private class DatabaseRegionSubscription: Subscription - where Downstream.Failure == Error, Downstream.Input == Database + where Downstream.Failure == any Error, Downstream.Input == Database { private struct WaitingForDemand { let downstream: Downstream @@ -298,7 +298,7 @@ extension DatabasePublishers { } } - private func receive(failure error: Error) { + private func receive(failure error: any Error) { lock.synchronized { if case let .observing(info) = state { state = .finished diff --git a/GRDB/Core/DatabaseSnapshot.swift b/GRDB/Core/DatabaseSnapshot.swift index 1381c1871..4811cc494 100644 --- a/GRDB/Core/DatabaseSnapshot.swift +++ b/GRDB/Core/DatabaseSnapshot.swift @@ -154,7 +154,7 @@ extension DatabaseSnapshot: DatabaseSnapshotReader { try reader.sync(block) } - public func asyncRead(_ value: @escaping (Result) -> Void) { + public func asyncRead(_ value: @escaping (Result) -> Void) { reader.async { value(.success($0)) } } @@ -162,7 +162,7 @@ extension DatabaseSnapshot: DatabaseSnapshotReader { try reader.sync(value) } - public func asyncUnsafeRead(_ value: @escaping (Result) -> Void) { + public func asyncUnsafeRead(_ value: @escaping (Result) -> Void) { reader.async { value(.success($0)) } } diff --git a/GRDB/Core/DatabaseSnapshotPool.swift b/GRDB/Core/DatabaseSnapshotPool.swift index c32b0b1a2..18f12bbdf 100644 --- a/GRDB/Core/DatabaseSnapshotPool.swift +++ b/GRDB/Core/DatabaseSnapshotPool.swift @@ -292,7 +292,7 @@ extension DatabaseSnapshotPool: DatabaseSnapshotReader { } } - public func asyncRead(_ value: @escaping (Result) -> Void) { + public func asyncRead(_ value: @escaping (Result) -> Void) { guard let readerPool else { value(.failure(DatabaseError.connectionIsClosed())) return diff --git a/GRDB/Core/DatabaseWriter.swift b/GRDB/Core/DatabaseWriter.swift index b4de8f6fd..055a5bf6f 100644 --- a/GRDB/Core/DatabaseWriter.swift +++ b/GRDB/Core/DatabaseWriter.swift @@ -181,7 +181,7 @@ public protocol DatabaseWriter: DatabaseReader { /// - parameter updates: A closure which accesses the database. Its argument /// is a `Result` that provides the database connection, or the failure /// that would prevent establishing the barrier access to the database. - func asyncBarrierWriteWithoutTransaction(_ updates: @escaping (Result) -> Void) + func asyncBarrierWriteWithoutTransaction(_ updates: @escaping (Result) -> Void) /// Schedules database operations for execution, and returns immediately. /// @@ -340,7 +340,7 @@ public protocol DatabaseWriter: DatabaseReader { /// - parameter value: A closure which accesses the database. Its argument /// is a `Result` that provides the database connection, or the failure /// that would prevent establishing the read access to the database. - func spawnConcurrentRead(_ value: @escaping (Result) -> Void) + func spawnConcurrentRead(_ value: @escaping (Result) -> Void) } extension DatabaseWriter { @@ -427,7 +427,7 @@ extension DatabaseWriter { /// - parameter completion: A closure called with the transaction result. public func asyncWrite( _ updates: @escaping (Database) throws -> T, - completion: @escaping (Database, Result) -> Void) + completion: @escaping (Database, Result) -> Void) { asyncWriteWithoutTransaction { db in do { @@ -906,9 +906,9 @@ extension DatabasePublishers { /// You build such a publisher from ``DatabaseWriter``. public struct Write: Publisher { public typealias Output = Output - public typealias Failure = Error + public typealias Failure = any Error - fileprivate let upstream: AnyPublisher + fileprivate let upstream: AnyPublisher public func receive(subscriber: S) where S: Subscriber, Self.Failure == S.Failure, Self.Output == S.Input { upstream.receive(subscriber: subscriber) @@ -917,7 +917,7 @@ extension DatabasePublishers { } @available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) -extension Publisher where Failure == Error { +extension Publisher where Failure == any Error { fileprivate func eraseToWritePublisher() -> DatabasePublishers.Write { .init(upstream: self.eraseToAnyPublisher()) } @@ -949,7 +949,7 @@ public class DatabaseFuture { _wait = wait } - init(_ result: Result) { + init(_ result: Result) { _wait = result.get } @@ -1003,7 +1003,7 @@ extension AnyDatabaseWriter: DatabaseReader { try base.read(value) } - public func asyncRead(_ value: @escaping (Result) -> Void) { + public func asyncRead(_ value: @escaping (Result) -> Void) { base.asyncRead(value) } @@ -1012,7 +1012,7 @@ extension AnyDatabaseWriter: DatabaseReader { try base.unsafeRead(value) } - public func asyncUnsafeRead(_ value: @escaping (Result) -> Void) { + public func asyncUnsafeRead(_ value: @escaping (Result) -> Void) { base.asyncUnsafeRead(value) } @@ -1044,7 +1044,7 @@ extension AnyDatabaseWriter: DatabaseWriter { try base.barrierWriteWithoutTransaction(updates) } - public func asyncBarrierWriteWithoutTransaction(_ updates: @escaping (Result) -> Void) { + public func asyncBarrierWriteWithoutTransaction(_ updates: @escaping (Result) -> Void) { base.asyncBarrierWriteWithoutTransaction(updates) } @@ -1060,7 +1060,7 @@ extension AnyDatabaseWriter: DatabaseWriter { base.concurrentRead(value) } - public func spawnConcurrentRead(_ value: @escaping (Result) -> Void) { + public func spawnConcurrentRead(_ value: @escaping (Result) -> Void) { base.spawnConcurrentRead(value) } } diff --git a/GRDB/Core/Support/Foundation/DatabaseDateComponents.swift b/GRDB/Core/Support/Foundation/DatabaseDateComponents.swift index 954edb350..ea4ca1e35 100644 --- a/GRDB/Core/Support/Foundation/DatabaseDateComponents.swift +++ b/GRDB/Core/Support/Foundation/DatabaseDateComponents.swift @@ -152,7 +152,7 @@ extension DatabaseDateComponents: DatabaseValueConvertible { } extension DatabaseDateComponents: Decodable { - public init(from decoder: Decoder) throws { + public init(from decoder: any Decoder) throws { let container = try decoder.singleValueContainer() let stringValue = try container.decode(String.self) guard let decodedValue = DatabaseDateComponents.fromDatabaseValue(stringValue.databaseValue) else { @@ -164,7 +164,7 @@ extension DatabaseDateComponents: Decodable { } extension DatabaseDateComponents: Encodable { - public func encode(to encoder: Encoder) throws { + public func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() try container.encode(String.fromDatabaseValue(databaseValue)!) } diff --git a/GRDB/Core/Support/StandardLibrary/DatabaseValueConvertible+Decodable.swift b/GRDB/Core/Support/StandardLibrary/DatabaseValueConvertible+Decodable.swift index 9e680f66b..b77ca487f 100644 --- a/GRDB/Core/Support/StandardLibrary/DatabaseValueConvertible+Decodable.swift +++ b/GRDB/Core/Support/StandardLibrary/DatabaseValueConvertible+Decodable.swift @@ -161,12 +161,12 @@ private struct DatabaseValueDecoder: Decoder { throw JSONRequiredError() } - func unkeyedContainer() throws -> UnkeyedDecodingContainer { + func unkeyedContainer() throws -> any UnkeyedDecodingContainer { // We need to switch to JSON decoding throw JSONRequiredError() } - func singleValueContainer() throws -> SingleValueDecodingContainer { + func singleValueContainer() throws -> any SingleValueDecodingContainer { DatabaseValueDecodingContainer(dbValue: dbValue, codingPath: codingPath) } } diff --git a/GRDB/Core/Support/StandardLibrary/DatabaseValueConvertible+Encodable.swift b/GRDB/Core/Support/StandardLibrary/DatabaseValueConvertible+Encodable.swift index 7735a8fb6..266f4ec80 100644 --- a/GRDB/Core/Support/StandardLibrary/DatabaseValueConvertible+Encodable.swift +++ b/GRDB/Core/Support/StandardLibrary/DatabaseValueConvertible+Encodable.swift @@ -92,7 +92,7 @@ private class DatabaseValueEncoder: Encoder { /// - precondition: May not be called after a prior `self.container(keyedBy:)` call. /// - precondition: May not be called after a value has been encoded through /// a previous `self.singleValueContainer()` call. - func unkeyedContainer() -> UnkeyedEncodingContainer { + func unkeyedContainer() -> any UnkeyedEncodingContainer { // We need to perform JSON encoding. Unfortunately we can't access the // inner container of Foundation's JSONEncoder. At this point we must // throw an error so that the caller can retry encoding from scratch. @@ -109,7 +109,7 @@ private class DatabaseValueEncoder: Encoder { /// - precondition: May not be called after a prior `self.unkeyedContainer()` call. /// - precondition: May not be called after a value has been encoded through /// a previous `self.singleValueContainer()` call. - func singleValueContainer() -> SingleValueEncodingContainer { + func singleValueContainer() -> any SingleValueEncodingContainer { DatabaseValueEncodingContainer(encode: encode, jsonEncoder: jsonEncoder) } diff --git a/GRDB/Core/Support/StandardLibrary/JSONRequiredEncoder.swift b/GRDB/Core/Support/StandardLibrary/JSONRequiredEncoder.swift index 96e9d041f..b019977a3 100644 --- a/GRDB/Core/Support/StandardLibrary/JSONRequiredEncoder.swift +++ b/GRDB/Core/Support/StandardLibrary/JSONRequiredEncoder.swift @@ -10,9 +10,9 @@ struct JSONRequiredEncoder: Encoder { return KeyedEncodingContainer(container) } - func unkeyedContainer() -> UnkeyedEncodingContainer { self } + func unkeyedContainer() -> any UnkeyedEncodingContainer { self } - func singleValueContainer() -> SingleValueEncodingContainer { self } + func singleValueContainer() -> any SingleValueEncodingContainer { self } struct KeyedContainer: KeyedEncodingContainerProtocol { var codingPath: [any CodingKey] @@ -47,15 +47,15 @@ struct JSONRequiredEncoder: Encoder { return KeyedEncodingContainer(container) } - func nestedUnkeyedContainer(forKey key: KeyType) -> UnkeyedEncodingContainer { + func nestedUnkeyedContainer(forKey key: KeyType) -> any UnkeyedEncodingContainer { JSONRequiredEncoder(codingPath: codingPath) } - func superEncoder() -> Encoder { + func superEncoder() -> any Encoder { JSONRequiredEncoder(codingPath: codingPath) } - func superEncoder(forKey key: KeyType) -> Encoder { + func superEncoder(forKey key: KeyType) -> any Encoder { JSONRequiredEncoder(codingPath: codingPath) } } @@ -91,7 +91,7 @@ extension JSONRequiredEncoder: UnkeyedEncodingContainer { return KeyedEncodingContainer(container) } - mutating func nestedUnkeyedContainer() -> UnkeyedEncodingContainer { self } + mutating func nestedUnkeyedContainer() -> any UnkeyedEncodingContainer { self } - mutating func superEncoder() -> Encoder { self } + mutating func superEncoder() -> any Encoder { self } } diff --git a/GRDB/Core/TransactionObserver.swift b/GRDB/Core/TransactionObserver.swift index 5330dfb5d..995515947 100644 --- a/GRDB/Core/TransactionObserver.swift +++ b/GRDB/Core/TransactionObserver.swift @@ -751,7 +751,7 @@ class DatabaseObservationBroker { /// Transaction turns rollbacked because a transaction observer has /// cancelled a commit by throwing an error. - case cancelledCommit(Error) + case cancelledCommit(any Error) } } diff --git a/GRDB/Fixits.swift b/GRDB/Fixits.swift index ed82d514d..2376328fd 100644 --- a/GRDB/Fixits.swift +++ b/GRDB/Fixits.swift @@ -58,7 +58,7 @@ extension DatabaseMigrator { @available(*, unavailable, message: "The completion function now accepts one Result argument") public func asyncMigrate( _ writer: any DatabaseWriter, - completion: @escaping (Database, Error?) -> Void) + completion: @escaping (Database, (any Error)?) -> Void) { preconditionFailure() } } diff --git a/GRDB/Migration/DatabaseMigrator.swift b/GRDB/Migration/DatabaseMigrator.swift index 9757c85b0..67673cb3e 100644 --- a/GRDB/Migration/DatabaseMigrator.swift +++ b/GRDB/Migration/DatabaseMigrator.swift @@ -264,7 +264,7 @@ public struct DatabaseMigrator { /// from succeeding. public func asyncMigrate( _ writer: some DatabaseWriter, - completion: @escaping (Result) -> Void) + completion: @escaping (Result) -> Void) { writer.asyncBarrierWriteWithoutTransaction { dbResult in do { @@ -523,9 +523,9 @@ extension DatabasePublishers { /// You build such a publisher from ``DatabaseMigrator``. public struct Migrate: Publisher { public typealias Output = Void - public typealias Failure = Error + public typealias Failure = any Error - fileprivate let upstream: AnyPublisher + fileprivate let upstream: AnyPublisher public func receive(subscriber: S) where S: Subscriber, Self.Failure == S.Failure, Self.Output == S.Input { upstream.receive(subscriber: subscriber) diff --git a/GRDB/QueryInterface/Schema/Database+SchemaDefinition.swift b/GRDB/QueryInterface/Schema/Database+SchemaDefinition.swift index eb62d7e88..7053afc8d 100644 --- a/GRDB/QueryInterface/Schema/Database+SchemaDefinition.swift +++ b/GRDB/QueryInterface/Schema/Database+SchemaDefinition.swift @@ -365,7 +365,7 @@ extension Database { view name: String, options: ViewOptions = [], columns: [String]? = nil, - as request: SQLSubqueryable) + as request: some SQLSubqueryable) throws { var literal: SQL = "CREATE " diff --git a/GRDB/Record/EncodableRecord+Encodable.swift b/GRDB/Record/EncodableRecord+Encodable.swift index c7816c672..8aad72698 100644 --- a/GRDB/Record/EncodableRecord+Encodable.swift +++ b/GRDB/Record/EncodableRecord+Encodable.swift @@ -29,11 +29,11 @@ private class RecordEncoder: Encoder { return KeyedEncodingContainer(container) } - func unkeyedContainer() -> UnkeyedEncodingContainer { + func unkeyedContainer() -> any UnkeyedEncodingContainer { fatalError("unkeyed encoding is not supported") } - func singleValueContainer() -> SingleValueEncodingContainer { + func singleValueContainer() -> any SingleValueEncodingContainer { // @itaiferber on https://forums.swift.org/t/how-to-encode-objects-of-unknown-type/12253/11 // // > Encoding a value into a single-value container is equivalent to @@ -109,15 +109,15 @@ private class RecordEncoder: Encoder { fatalError("Not implemented") } - func nestedUnkeyedContainer(forKey key: Key) -> UnkeyedEncodingContainer { + func nestedUnkeyedContainer(forKey key: Key) -> any UnkeyedEncodingContainer { fatalError("Not implemented") } - func superEncoder() -> Encoder { + func superEncoder() -> any Encoder { recordEncoder } - func superEncoder(forKey key: Key) -> Encoder { + func superEncoder(forKey key: Key) -> any Encoder { recordEncoder } } @@ -195,7 +195,7 @@ private class ColumnEncoder: Encoder { return KeyedEncodingContainer(container) } - func unkeyedContainer() -> UnkeyedEncodingContainer { + func unkeyedContainer() -> any UnkeyedEncodingContainer { // We need to perform JSON encoding. Unfortunately we can't access the // inner container of Foundation's JSONEncoder. At this point we must // throw an error so that the caller can retry encoding from scratch. @@ -205,7 +205,7 @@ private class ColumnEncoder: Encoder { return JSONRequiredEncoder(codingPath: codingPath) } - func singleValueContainer() -> SingleValueEncodingContainer { self } + func singleValueContainer() -> any SingleValueEncodingContainer { self } } extension ColumnEncoder: SingleValueEncodingContainer { diff --git a/GRDB/Record/FetchableRecord+Decodable.swift b/GRDB/Record/FetchableRecord+Decodable.swift index e1d7db715..1fc020391 100644 --- a/GRDB/Record/FetchableRecord+Decodable.swift +++ b/GRDB/Record/FetchableRecord+Decodable.swift @@ -79,7 +79,7 @@ public class FetchableRecordDecoder { /// The decoder that decodes a record from a database row private struct _RowDecoder: Decoder { var row: Row - var codingPath: [CodingKey] + var codingPath: [any CodingKey] var columnDecodingStrategy: DatabaseColumnDecodingStrategy var userInfo: [CodingUserInfoKey: Any] { R.databaseDecodingUserInfo } @@ -87,7 +87,7 @@ private struct _RowDecoder: Decoder { KeyedDecodingContainer(KeyedContainer(decoder: self)) } - func unkeyedContainer() throws -> UnkeyedDecodingContainer { + func unkeyedContainer() throws -> any UnkeyedDecodingContainer { guard let codingKey = codingPath.last else { fatalError("unkeyed decoding from database row is not supported") } @@ -105,7 +105,7 @@ private struct _RowDecoder: Decoder { debugDescription: debugDescription)) } - func singleValueContainer() throws -> SingleValueDecodingContainer { + func singleValueContainer() throws -> any SingleValueDecodingContainer { guard let key = codingPath.last else { // Decoding an array of scalars from rows: pick the first column return ColumnDecoder(row: row, columnIndex: 0, codingPath: codingPath) @@ -123,8 +123,8 @@ private struct _RowDecoder: Decoder { class KeyedContainer: KeyedDecodingContainerProtocol { private let decoder: _RowDecoder - var codingPath: [CodingKey] { decoder.codingPath } - private var decodedRootKey: CodingKey? + var codingPath: [any CodingKey] { decoder.codingPath } + private var decodedRootKey: (any CodingKey)? // Not nil iff decoder has a columnDecodingStrategy private let _columnForKey: [String: String]? @@ -378,17 +378,17 @@ private struct _RowDecoder: Decoder { fatalError("not implemented") } - func nestedUnkeyedContainer(forKey key: Key) throws -> UnkeyedDecodingContainer { + func nestedUnkeyedContainer(forKey key: Key) throws -> any UnkeyedDecodingContainer { throw DecodingError.typeMismatch( - UnkeyedDecodingContainer.self, + (any UnkeyedDecodingContainer).self, DecodingError.Context(codingPath: codingPath, debugDescription: "unkeyed decoding is not supported")) } - func superDecoder() throws -> Decoder { + func superDecoder() throws -> any Decoder { decoder } - func superDecoder(forKey key: Key) throws -> Decoder { + func superDecoder(forKey key: Key) throws -> any Decoder { decoder } @@ -397,7 +397,7 @@ private struct _RowDecoder: Decoder { private func decode( _ type: T.Type, fromRow row: Row, - codingPath: [CodingKey]) + codingPath: [any CodingKey]) throws -> T where T: Decodable { @@ -449,11 +449,11 @@ private struct _RowDecoder: Decoder { private struct PrefetchedRowsDecoder: Decoder { var rows: [Row] - var codingPath: [CodingKey] + var codingPath: [any CodingKey] var currentIndex: Int var userInfo: [CodingUserInfoKey: Any] { R.databaseDecodingUserInfo } - init(rows: [Row], codingPath: [CodingKey]) { + init(rows: [Row], codingPath: [any CodingKey]) { self.rows = rows self.codingPath = codingPath self.currentIndex = 0 @@ -463,9 +463,9 @@ private struct PrefetchedRowsDecoder: Decoder { fatalError("keyed decoding from prefetched rows is not supported") } - func unkeyedContainer() throws -> UnkeyedDecodingContainer { self } + func unkeyedContainer() throws -> any UnkeyedDecodingContainer { self } - func singleValueContainer() throws -> SingleValueDecodingContainer { + func singleValueContainer() throws -> any SingleValueDecodingContainer { fatalError("single value decoding from prefetched rows is not supported") } } @@ -501,11 +501,11 @@ extension PrefetchedRowsDecoder: UnkeyedDecodingContainer { fatalError("not implemented") } - mutating func nestedUnkeyedContainer() throws -> UnkeyedDecodingContainer { + mutating func nestedUnkeyedContainer() throws -> any UnkeyedDecodingContainer { fatalError("not implemented") } - mutating func superDecoder() throws -> Decoder { + mutating func superDecoder() throws -> any Decoder { fatalError("not implemented") } } @@ -516,7 +516,7 @@ extension PrefetchedRowsDecoder: UnkeyedDecodingContainer { private struct ColumnDecoder: Decoder { var row: Row var columnIndex: Int - var codingPath: [CodingKey] + var codingPath: [any CodingKey] var userInfo: [CodingUserInfoKey: Any] { R.databaseDecodingUserInfo } func container(keyedBy type: Key.Type) throws -> KeyedDecodingContainer { @@ -524,12 +524,12 @@ private struct ColumnDecoder: Decoder { throw JSONRequiredError() } - func unkeyedContainer() throws -> UnkeyedDecodingContainer { + func unkeyedContainer() throws -> any UnkeyedDecodingContainer { // We need to switch to JSON decoding throw JSONRequiredError() } - func singleValueContainer() throws -> SingleValueDecodingContainer { self } + func singleValueContainer() throws -> any SingleValueDecodingContainer { self } } extension ColumnDecoder: SingleValueDecodingContainer { diff --git a/GRDB/Record/FetchableRecord.swift b/GRDB/Record/FetchableRecord.swift index 9a5c5679b..c36fe41c9 100644 --- a/GRDB/Record/FetchableRecord.swift +++ b/GRDB/Record/FetchableRecord.swift @@ -967,7 +967,7 @@ public enum DatabaseColumnDecodingStrategy { case convertFromSnakeCase /// A key decoding strategy defined by the closure you supply. - case custom((String) -> CodingKey) + case custom((String) -> any CodingKey) func key(forColumn column: String) -> K? { switch self { diff --git a/GRDB/Utils/Pool.swift b/GRDB/Utils/Pool.swift index 6e1014c75..9dba92203 100644 --- a/GRDB/Utils/Pool.swift +++ b/GRDB/Utils/Pool.swift @@ -107,7 +107,7 @@ final class Pool { /// /// - important: The `execute` argument is executed in a serial dispatch /// queue, so make sure you use the element asynchronously. - func asyncGet(_ execute: @escaping (Result<(element: T, release: (PoolCompletion) -> Void), Error>) -> Void) { + func asyncGet(_ execute: @escaping (Result<(element: T, release: (PoolCompletion) -> Void), any Error>) -> Void) { // Inspired by https://khanlou.com/2016/04/the-GCD-handbook/ // > We wait on the semaphore in the serial queue, which means that // > we’ll have at most one blocked thread when we reach maximum diff --git a/GRDB/Utils/ReceiveValuesOn.swift b/GRDB/Utils/ReceiveValuesOn.swift index abc688f78..502417c45 100644 --- a/GRDB/Utils/ReceiveValuesOn.swift +++ b/GRDB/Utils/ReceiveValuesOn.swift @@ -48,7 +48,7 @@ where private enum State { case waitingForRequest(Upstream, Target) case waitingForSubscription(Target, Subscribers.Demand) - case subscribed(Target, Subscription) + case subscribed(Target, any Subscription) case finished } @@ -110,7 +110,7 @@ where // MARK: Subscriber - func receive(subscription: Subscription) { + func receive(subscription: any Subscription) { lock.synchronized { sideEffect in switch state { case let .waitingForSubscription(target, currentDemand): diff --git a/GRDB/Utils/Utils.swift b/GRDB/Utils/Utils.swift index 90e3ca557..881193137 100644 --- a/GRDB/Utils/Utils.swift +++ b/GRDB/Utils/Utils.swift @@ -99,7 +99,7 @@ extension Sequence { /// finally: cleanup) func throwingFirstError(execute: () throws -> T, finally: () throws -> Void) throws -> T { var result: T? - var firstError: Error? + var firstError: (any Error)? do { result = try execute() } catch { diff --git a/GRDB/ValueObservation/Observers/ValueConcurrentObserver.swift b/GRDB/ValueObservation/Observers/ValueConcurrentObserver.swift index d9a81fd50..e8075f00f 100644 --- a/GRDB/ValueObservation/Observers/ValueConcurrentObserver.swift +++ b/GRDB/ValueObservation/Observers/ValueConcurrentObserver.swift @@ -817,7 +817,7 @@ extension ValueConcurrentObserver: TransactionObserver { } } - private func reduce(_ fetchResult: Result) { + private func reduce(_ fetchResult: Result) { reduceQueue.async { do { let fetchedValue = try fetchResult.get() @@ -874,7 +874,7 @@ extension ValueConcurrentObserver: DatabaseCancellable { } } - func notifyError(_ error: Error) { + func notifyError(_ error: any Error) { scheduler.schedule { let events = self.lock.synchronized { let events = self.notificationCallbacks?.events diff --git a/GRDB/ValueObservation/Observers/ValueWriteOnlyObserver.swift b/GRDB/ValueObservation/Observers/ValueWriteOnlyObserver.swift index c81ac1bcc..1c2e69504 100644 --- a/GRDB/ValueObservation/Observers/ValueWriteOnlyObserver.swift +++ b/GRDB/ValueObservation/Observers/ValueWriteOnlyObserver.swift @@ -457,7 +457,7 @@ extension ValueWriteOnlyObserver: DatabaseCancellable { } } - func notifyError(_ error: Error) { + func notifyError(_ error: any Error) { scheduler.schedule { let events = self.lock.synchronized { let events = self.notificationCallbacks?.events diff --git a/GRDB/ValueObservation/SharedValueObservation.swift b/GRDB/ValueObservation/SharedValueObservation.swift index 123c44c28..c327163a7 100644 --- a/GRDB/ValueObservation/SharedValueObservation.swift +++ b/GRDB/ValueObservation/SharedValueObservation.swift @@ -177,13 +177,13 @@ public final class SharedValueObservation { private var clients: [Client] private var isObserving = false private var cancellable: AnyDatabaseCancellable? - private var lastResult: Result? + private var lastResult: Result? private final class Client { - var onError: (Error) -> Void + var onError: (any Error) -> Void var onChange: (Element) -> Void - init(onError: @escaping (Error) -> Void, onChange: @escaping (Element) -> Void) { + init(onError: @escaping (any Error) -> Void, onChange: @escaping (Element) -> Void) { self.onError = onError self.onChange = onChange } @@ -224,7 +224,7 @@ public final class SharedValueObservation { /// fresh value. /// - returns: A DatabaseCancellable that can stop the observation. public func start( - onError: @escaping (Error) -> Void, + onError: @escaping (any Error) -> Void, onChange: @escaping (Element) -> Void) -> AnyDatabaseCancellable { @@ -299,7 +299,7 @@ public final class SharedValueObservation { } #endif - private func handleError(_ error: Error) { + private func handleError(_ error: any Error) { synchronized { let notifiedClients = clients diff --git a/GRDB/ValueObservation/ValueObservation.swift b/GRDB/ValueObservation/ValueObservation.swift index 696eae6a1..85da4780a 100644 --- a/GRDB/ValueObservation/ValueObservation.swift +++ b/GRDB/ValueObservation/ValueObservation.swift @@ -77,12 +77,12 @@ struct ValueObservationEvents: Refinable { var willStart: (() -> Void)? var willTrackRegion: ((DatabaseRegion) -> Void)? var databaseDidChange: (() -> Void)? - var didFail: ((Error) -> Void)? + var didFail: ((any Error) -> Void)? var didCancel: (() -> Void)? } typealias ValueObservationStart = ( - _ onError: @escaping (Error) -> Void, + _ onError: @escaping (any Error) -> Void, _ onChange: @escaping (T) -> Void) -> AnyDatabaseCancellable @@ -138,7 +138,7 @@ extension ValueObservation: Refinable { public func start( in reader: some DatabaseReader, scheduling scheduler: some ValueObservationScheduler = .async(onQueue: .main), - onError: @escaping (Error) -> Void, + onError: @escaping (any Error) -> Void, onChange: @escaping (Reducer.Value) -> Void) -> AnyDatabaseCancellable where Reducer: ValueReducer @@ -180,7 +180,7 @@ extension ValueObservation: Refinable { willTrackRegion: ((DatabaseRegion) -> Void)? = nil, databaseDidChange: (() -> Void)? = nil, didReceiveValue: ((Reducer.Value) -> Void)? = nil, - didFail: ((Error) -> Void)? = nil, + didFail: ((any Error) -> Void)? = nil, didCancel: (() -> Void)? = nil) -> ValueObservation> { @@ -231,7 +231,7 @@ extension ValueObservation: Refinable { /// used to log messages to other destinations. public func print( _ prefix: String = "", - to stream: TextOutputStream? = nil) + to stream: (any TextOutputStream)? = nil) -> ValueObservation> { let lock = NSLock() @@ -333,7 +333,7 @@ extension ValueObservation { /// ``SharedValueObservation``. @available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) public struct AsyncValueObservation: AsyncSequence { - public typealias BufferingPolicy = AsyncThrowingStream.Continuation.BufferingPolicy + public typealias BufferingPolicy = AsyncThrowingStream.Continuation.BufferingPolicy public typealias AsyncIterator = Iterator var bufferingPolicy: BufferingPolicy @@ -377,7 +377,7 @@ public struct AsyncValueObservation: AsyncSequence { } public struct Iterator: AsyncIteratorProtocol { - var iterator: AsyncThrowingStream.AsyncIterator + var iterator: AsyncThrowingStream.AsyncIterator let cancellable: AnyDatabaseCancellable public mutating func next() async throws -> Element? { @@ -457,7 +457,7 @@ extension DatabasePublishers { /// You build such a publisher from ``ValueObservation`` /// or ``SharedValueObservation``. public struct Value: Publisher { - public typealias Failure = Error + public typealias Failure = any Error private let start: ValueObservationStart init(start: @escaping ValueObservationStart) { @@ -473,7 +473,7 @@ extension DatabasePublishers { } private class ValueSubscription: Subscription - where Downstream.Failure == Error + where Downstream.Failure == any Error { private struct WaitingForDemand { let downstream: Downstream diff --git a/Package.swift b/Package.swift index dfd0d59fa..f8b89c9e4 100644 --- a/Package.swift +++ b/Package.swift @@ -10,9 +10,6 @@ var swiftSettings: [SwiftSetting] = [ var cSettings: [CSetting] = [] var dependencies: [PackageDescription.Package.Dependency] = [] -// For Swift 5.8+ -//swiftSettings.append(.enableUpcomingFeature("ExistentialAny")) - // Don't rely on those environment variables. They are ONLY testing conveniences: // $ SQLITE_ENABLE_PREUPDATE_HOOK=1 make test_SPM if ProcessInfo.processInfo.environment["SQLITE_ENABLE_PREUPDATE_HOOK"] == "1" { @@ -77,6 +74,5 @@ let package = Package( ], cSettings: cSettings, swiftSettings: swiftSettings) - ], - swiftLanguageVersions: [.v5] + ] ) diff --git a/Package@swift-5.9.swift b/Package@swift-5.9.swift new file mode 100644 index 000000000..c12ef543a --- /dev/null +++ b/Package@swift-5.9.swift @@ -0,0 +1,80 @@ +// swift-tools-version:5.9 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import Foundation +import PackageDescription + +var swiftSettings: [SwiftSetting] = [ + .define("SQLITE_ENABLE_FTS5"), + // + .enableUpcomingFeature("ExistentialAny"), +] +var cSettings: [CSetting] = [] +var dependencies: [PackageDescription.Package.Dependency] = [] + +// Don't rely on those environment variables. They are ONLY testing conveniences: +// $ SQLITE_ENABLE_PREUPDATE_HOOK=1 make test_SPM +if ProcessInfo.processInfo.environment["SQLITE_ENABLE_PREUPDATE_HOOK"] == "1" { + swiftSettings.append(.define("SQLITE_ENABLE_PREUPDATE_HOOK")) + cSettings.append(.define("GRDB_SQLITE_ENABLE_PREUPDATE_HOOK")) +} + +// The SPI_BUILDER environment variable enables documentation building +// on . See +// +// for more information. +// +// SPI_BUILDER also enables the `make docs-localhost` command. +if ProcessInfo.processInfo.environment["SPI_BUILDER"] == "1" { + dependencies.append(.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0")) +} + +let package = Package( + name: "GRDB", + defaultLocalization: "en", // for tests + platforms: [ + .iOS(.v11), + .macOS(.v10_13), + .tvOS(.v11), + .watchOS(.v4), + ], + products: [ + .library(name: "CSQLite", targets: ["CSQLite"]), + .library(name: "GRDB", targets: ["GRDB"]), + .library(name: "GRDB-dynamic", type: .dynamic, targets: ["GRDB"]), + ], + dependencies: dependencies, + targets: [ + .systemLibrary( + name: "CSQLite", + providers: [.apt(["libsqlite3-dev"])]), + .target( + name: "GRDB", + dependencies: ["CSQLite"], + path: "GRDB", + cSettings: cSettings, + swiftSettings: swiftSettings), + .testTarget( + name: "GRDBTests", + dependencies: ["GRDB"], + path: "Tests", + exclude: [ + "CocoaPods", + "Crash", + "CustomSQLite", + "GRDBTests/getThreadsCount.c", + "Info.plist", + "Performance", + "SPM", + "generatePerformanceReport.rb", + "parsePerformanceTests.rb", + ], + resources: [ + .copy("GRDBTests/Betty.jpeg"), + .copy("GRDBTests/InflectionsTests.json"), + .copy("GRDBTests/Issue1383.sqlite"), + ], + cSettings: cSettings, + swiftSettings: swiftSettings) + ] +) diff --git a/Tests/CombineExpectations/Recorder.swift b/Tests/CombineExpectations/Recorder.swift index 48e981b27..6908e3ba2 100644 --- a/Tests/CombineExpectations/Recorder.swift +++ b/Tests/CombineExpectations/Recorder.swift @@ -40,7 +40,7 @@ public class Recorder: Subscriber { /// Publisher is subscribed. The recorder may have an expectation to /// fulfill. It keeps track of all published elements. - case subscribed(Subscription, RecorderExpectation?, [Input]) + case subscribed(any Subscription, RecorderExpectation?, [Input]) /// Publisher is completed. The recorder keeps track of all published /// elements and completion. @@ -204,7 +204,7 @@ public class Recorder: Subscriber { // MARK: - Subscriber - public func receive(subscription: Subscription) { + public func receive(subscription: any Subscription) { synchronized { switch state { case let .waitingForSubscription(exp): diff --git a/Tests/GRDBCombineTests/DatabaseRegionObservationPublisherTests.swift b/Tests/GRDBCombineTests/DatabaseRegionObservationPublisherTests.swift index e126c54b3..8ff504f3f 100644 --- a/Tests/GRDBCombineTests/DatabaseRegionObservationPublisherTests.swift +++ b/Tests/GRDBCombineTests/DatabaseRegionObservationPublisherTests.swift @@ -72,7 +72,7 @@ class DatabaseRegionObservationPublisherTests : XCTestCase { func test(writer: some DatabaseWriter) throws { let expectation = self.expectation(description: "") - let testSubject = PassthroughSubject() + let testSubject = PassthroughSubject() let testCancellable = testSubject .tryMap(Player.fetchCount) .collect(3) diff --git a/Tests/GRDBCombineTests/DatabaseWriterWritePublisherTests.swift b/Tests/GRDBCombineTests/DatabaseWriterWritePublisherTests.swift index 1ab142081..1e168efd8 100644 --- a/Tests/GRDBCombineTests/DatabaseWriterWritePublisherTests.swift +++ b/Tests/GRDBCombineTests/DatabaseWriterWritePublisherTests.swift @@ -397,7 +397,7 @@ class DatabaseWriterWritePublisherTests : XCTestCase { func test(writer: some DatabaseWriter, iteration: Int) throws { // print(iteration) - let scoreSubject = PassthroughSubject() + let scoreSubject = PassthroughSubject() let publisher = scoreSubject .map { score in writer.writePublisher { db -> Int in diff --git a/Tests/GRDBCombineTests/ValueObservationPublisherTests.swift b/Tests/GRDBCombineTests/ValueObservationPublisherTests.swift index b55fd98c6..5cc852bf6 100644 --- a/Tests/GRDBCombineTests/ValueObservationPublisherTests.swift +++ b/Tests/GRDBCombineTests/ValueObservationPublisherTests.swift @@ -176,7 +176,7 @@ class ValueObservationPublisherTests : XCTestCase { func test(writer: some DatabaseWriter) throws { let semaphore = DispatchSemaphore(value: 0) - let testSubject = PassthroughSubject() + let testSubject = PassthroughSubject() let testCancellable = testSubject .sink( receiveCompletion: { _ in }, @@ -228,7 +228,7 @@ class ValueObservationPublisherTests : XCTestCase { @available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *) private class DemandSubscriber: Subscriber { - private var subscription: Subscription? + private var subscription: (any Subscription)? let subject = PassthroughSubject() deinit { subscription?.cancel() @@ -242,7 +242,7 @@ class ValueObservationPublisherTests : XCTestCase { subscription!.request(demand) } - func receive(subscription: Subscription) { + func receive(subscription: any Subscription) { self.subscription = subscription } @@ -267,7 +267,7 @@ class ValueObservationPublisherTests : XCTestCase { } func test(writer: some DatabaseWriter) throws { - let subscriber = DemandSubscriber() + let subscriber = DemandSubscriber() let expectation = self.expectation(description: "") expectation.isInverted = true @@ -302,7 +302,7 @@ class ValueObservationPublisherTests : XCTestCase { } func test(writer: some DatabaseWriter) throws { - let subscriber = DemandSubscriber() + let subscriber = DemandSubscriber() let expectation = self.expectation(description: "") let testCancellable = subscriber.subject.sink( @@ -340,7 +340,7 @@ class ValueObservationPublisherTests : XCTestCase { } func test(writer: some DatabaseWriter) throws { - let subscriber = DemandSubscriber() + let subscriber = DemandSubscriber() let expectation = self.expectation(description: "") expectation.isInverted = true @@ -382,7 +382,7 @@ class ValueObservationPublisherTests : XCTestCase { } func test(writer: some DatabaseWriter) throws { - let subscriber = DemandSubscriber() + let subscriber = DemandSubscriber() let expectation = self.expectation(description: "") let testCancellable = subscriber.subject diff --git a/Tests/GRDBTests/AssociationPrefetchingCodableRecordTests.swift b/Tests/GRDBTests/AssociationPrefetchingCodableRecordTests.swift index 7877a5e2d..67f07fc0d 100644 --- a/Tests/GRDBTests/AssociationPrefetchingCodableRecordTests.swift +++ b/Tests/GRDBTests/AssociationPrefetchingCodableRecordTests.swift @@ -127,7 +127,7 @@ class AssociationPrefetchingCodableRecordTests: GRDBTestCase { } enum CodingKeys: CodingKey { case a, bs } - init(from decoder: Decoder) throws { + init(from decoder: any Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) a = try container.decode(A.self, forKey: .a) if try container.decodeNil(forKey: .bs) { @@ -307,7 +307,7 @@ class AssociationPrefetchingCodableRecordTests: GRDBTestCase { } enum CodingKeys: CodingKey { case a, bs } - init(from decoder: Decoder) throws { + init(from decoder: any Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) a = try container.decode(A.self, forKey: .a) if try container.decodeNil(forKey: .bs) { diff --git a/Tests/GRDBTests/DatabasePoolConcurrencyTests.swift b/Tests/GRDBTests/DatabasePoolConcurrencyTests.swift index 7a329c38c..595c7e2d2 100644 --- a/Tests/GRDBTests/DatabasePoolConcurrencyTests.swift +++ b/Tests/GRDBTests/DatabasePoolConcurrencyTests.swift @@ -1334,7 +1334,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { // of NSFileCoordinator. What a weird API. let coordinator = NSFileCoordinator(filePresenter: nil) var coordinatorError: NSError? - var poolError: Error? + var poolError: (any Error)? coordinator.coordinate(writingItemAt: dbURL, options: .forMerging, error: &coordinatorError) { url in do { _ = try DatabasePool(path: url.path) @@ -1355,7 +1355,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { let coordinator = NSFileCoordinator(filePresenter: nil) var coordinatorError: NSError? var dbPool: DatabasePool? - var dbError: Error? + var dbError: (any Error)? coordinator.coordinate(writingItemAt: databaseURL, options: .forMerging, error: &coordinatorError) { url in do { dbPool = try openDatabase(at: url) @@ -1384,7 +1384,7 @@ class DatabasePoolConcurrencyTests: GRDBTestCase { let coordinator = NSFileCoordinator(filePresenter: nil) var coordinatorError: NSError? var dbPool: DatabasePool? - var dbError: Error? + var dbError: (any Error)? coordinator.coordinate(readingItemAt: databaseURL, options: .withoutChanges, error: &coordinatorError) { url in do { dbPool = try openReadOnlyDatabase(at: url) diff --git a/Tests/GRDBTests/DatabaseValueConvertibleDecodableTests.swift b/Tests/GRDBTests/DatabaseValueConvertibleDecodableTests.swift index 50d495259..bd56c3eab 100644 --- a/Tests/GRDBTests/DatabaseValueConvertibleDecodableTests.swift +++ b/Tests/GRDBTests/DatabaseValueConvertibleDecodableTests.swift @@ -6,7 +6,7 @@ class DatabaseValueConvertibleDecodableTests: GRDBTestCase { struct Value : Decodable, DatabaseValueConvertible { let string: String - init(from decoder: Decoder) throws { + init(from decoder: any Decoder) throws { string = try decoder.singleValueContainer().decode(String.self) } @@ -42,7 +42,7 @@ class DatabaseValueConvertibleDecodableTests: GRDBTestCase { struct Value : Decodable, DatabaseValueConvertible { let string: String - init(from decoder: Decoder) throws { + init(from decoder: any Decoder) throws { string = try decoder.singleValueContainer().decode(String.self) } @@ -54,7 +54,7 @@ class DatabaseValueConvertibleDecodableTests: GRDBTestCase { struct ValueWrapper : Decodable, DatabaseValueConvertible { let value: Value - init(from decoder: Decoder) throws { + init(from decoder: any Decoder) throws { value = try decoder.singleValueContainer().decode(Value.self) } @@ -91,13 +91,13 @@ class DatabaseValueConvertibleDecodableTests: GRDBTestCase { struct Nested : Decodable { let string: String - init(from decoder: Decoder) throws { + init(from decoder: any Decoder) throws { string = try decoder.singleValueContainer().decode(String.self) } } let nested: Nested - init(from decoder: Decoder) throws { + init(from decoder: any Decoder) throws { nested = try decoder.singleValueContainer().decode(Nested.self) } @@ -162,7 +162,7 @@ class DatabaseValueConvertibleDecodableTests: GRDBTestCase { struct Value: Decodable, DatabaseValueConvertible { let dictionary: [String: Int] - init(from decoder: Decoder) throws { + init(from decoder: any Decoder) throws { dictionary = try .init(from: decoder) } @@ -195,7 +195,7 @@ class DatabaseValueConvertibleDecodableTests: GRDBTestCase { struct Value: Decodable, DatabaseValueConvertible { let strings: [String] - init(from decoder: Decoder) throws { + init(from decoder: any Decoder) throws { strings = try .init(from: decoder) } @@ -228,7 +228,7 @@ class DatabaseValueConvertibleDecodableTests: GRDBTestCase { struct Value: Decodable, DatabaseValueConvertible { let dictionary: [String: Int] - init(from decoder: Decoder) throws { + init(from decoder: any Decoder) throws { let container = try decoder.singleValueContainer() dictionary = try container.decode([String: Int].self) } @@ -262,7 +262,7 @@ class DatabaseValueConvertibleDecodableTests: GRDBTestCase { struct Value: Decodable, DatabaseValueConvertible { let strings: [String] - init(from decoder: Decoder) throws { + init(from decoder: any Decoder) throws { let container = try decoder.singleValueContainer() strings = try container.decode([String].self) } diff --git a/Tests/GRDBTests/DatabaseValueConvertibleEncodableTests.swift b/Tests/GRDBTests/DatabaseValueConvertibleEncodableTests.swift index 00f44620f..cee7f18c5 100644 --- a/Tests/GRDBTests/DatabaseValueConvertibleEncodableTests.swift +++ b/Tests/GRDBTests/DatabaseValueConvertibleEncodableTests.swift @@ -7,7 +7,7 @@ class DatabaseValueConvertibleEncodableTests: GRDBTestCase { struct Value : Encodable, DatabaseValueConvertible { let string: String - func encode(to encoder: Encoder) throws { + func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() try container.encode(string) } @@ -28,7 +28,7 @@ class DatabaseValueConvertibleEncodableTests: GRDBTestCase { struct Value : Encodable, DatabaseValueConvertible { let string: String - func encode(to encoder: Encoder) throws { + func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() try container.encode(string) } @@ -41,7 +41,7 @@ class DatabaseValueConvertibleEncodableTests: GRDBTestCase { struct Wrapper : Encodable, DatabaseValueConvertible { let value: Value - func encode(to encoder: Encoder) throws { + func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() try container.encode(value) } @@ -63,14 +63,14 @@ class DatabaseValueConvertibleEncodableTests: GRDBTestCase { struct Nested : Encodable { let string: String - func encode(to encoder: Encoder) throws { + func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() try container.encode(string) } } let nested: Nested - func encode(to encoder: Encoder) throws { + func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() try container.encode(nested) } @@ -111,7 +111,7 @@ class DatabaseValueConvertibleEncodableTests: GRDBTestCase { struct Value: Encodable, DatabaseValueConvertible { let dictionary: [String: Int] - func encode(to encoder: Encoder) throws { + func encode(to encoder: any Encoder) throws { try dictionary.encode(to: encoder) } @@ -135,7 +135,7 @@ class DatabaseValueConvertibleEncodableTests: GRDBTestCase { struct Value: Encodable, DatabaseValueConvertible { let strings: [String] - func encode(to encoder: Encoder) throws { + func encode(to encoder: any Encoder) throws { try strings.encode(to: encoder) } @@ -159,7 +159,7 @@ class DatabaseValueConvertibleEncodableTests: GRDBTestCase { struct Value: Encodable, DatabaseValueConvertible { let dictionary: [String: Int] - func encode(to encoder: Encoder) throws { + func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() try container.encode(dictionary) } @@ -184,7 +184,7 @@ class DatabaseValueConvertibleEncodableTests: GRDBTestCase { struct Value: Encodable, DatabaseValueConvertible { let strings: [String] - func encode(to encoder: Encoder) throws { + func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() try container.encode(strings) } @@ -232,7 +232,7 @@ extension DatabaseValueConvertibleEncodableTests { struct Value : Encodable, DatabaseValueConvertible { let date: Date - func encode(to encoder: Encoder) throws { + func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() try container.encode(date) } @@ -261,7 +261,7 @@ extension DatabaseValueConvertibleEncodableTests { struct Value : Encodable, DatabaseValueConvertible { let url: URL - func encode(to encoder: Encoder) throws { + func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() try container.encode(url) } @@ -285,7 +285,7 @@ extension DatabaseValueConvertibleEncodableTests { struct Value : Encodable, DatabaseValueConvertible { let uuid: UUID - func encode(to encoder: Encoder) throws { + func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() try container.encode(uuid) } diff --git a/Tests/GRDBTests/FetchableRecordDecodableTests.swift b/Tests/GRDBTests/FetchableRecordDecodableTests.swift index 2e2a3321d..7154d9209 100644 --- a/Tests/GRDBTests/FetchableRecordDecodableTests.swift +++ b/Tests/GRDBTests/FetchableRecordDecodableTests.swift @@ -27,7 +27,7 @@ extension FetchableRecordDecodableTests { case value = "someColumn" } - init(from decoder: Decoder) throws { + init(from decoder: any Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) value = try container.decode(String.self, forKey: .value) } @@ -89,7 +89,7 @@ extension FetchableRecordDecodableTests { struct Value : Decodable { let string: String - init(from decoder: Decoder) throws { + init(from decoder: any Decoder) throws { string = try decoder.singleValueContainer().decode(String.self) } } @@ -125,7 +125,7 @@ extension FetchableRecordDecodableTests { struct NestedValue : Decodable { let string: String - init(from decoder: Decoder) throws { + init(from decoder: any Decoder) throws { string = try decoder.singleValueContainer().decode(String.self) } } @@ -133,7 +133,7 @@ extension FetchableRecordDecodableTests { struct Value : Decodable { let nestedValue: NestedValue - init(from decoder: Decoder) throws { + init(from decoder: any Decoder) throws { nestedValue = try decoder.singleValueContainer().decode(NestedValue.self) } } @@ -214,7 +214,7 @@ extension FetchableRecordDecodableTests { self.string = string } - init(from decoder: Decoder) throws { + init(from decoder: any Decoder) throws { string = try decoder.singleValueContainer().decode(String.self) + " (Decodable)" } @@ -1084,7 +1084,7 @@ extension FetchableRecordDecodableTests { enum CodingKeys: String, CodingKey { case name } - init(from decoder: Decoder) throws { + init(from decoder: any Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) name = try container.decode(String.self, forKey: .name) key = decoder.codingPath.last?.stringValue @@ -1097,7 +1097,7 @@ extension FetchableRecordDecodableTests { var key: String? var context: String? - init(from decoder: Decoder) throws { + init(from decoder: any Decoder) throws { let container = try decoder.singleValueContainer() name = try container.decode(String.self) key = decoder.codingPath.last?.stringValue @@ -1110,7 +1110,7 @@ extension FetchableRecordDecodableTests { var key: String? var context: String? - init(from decoder: Decoder) throws { + init(from decoder: any Decoder) throws { var container = try decoder.unkeyedContainer() name = try container.decode(String.self) key = decoder.codingPath.last?.stringValue @@ -1129,7 +1129,7 @@ extension FetchableRecordDecodableTests { case nestedKeyed, nestedSingle, nestedUnkeyed } - init(from decoder: Decoder) throws { + init(from decoder: any Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) nestedKeyed = try container.decode(NestedKeyed.self, forKey: .nestedKeyed) nestedSingle = try container.decode(NestedSingle.self, forKey: .nestedSingle) @@ -1150,7 +1150,7 @@ extension FetchableRecordDecodableTests { case nestedKeyed, nestedSingle, nestedUnkeyed } - required init(from decoder: Decoder) throws { + required init(from decoder: any Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) nestedKeyed = try container.decode(NestedKeyed.self, forKey: .nestedKeyed) nestedSingle = try container.decode(NestedSingle.self, forKey: .nestedSingle) @@ -1448,7 +1448,7 @@ extension FetchableRecordDecodableTests { self.lastName = lastName } - init(from decoder: Decoder) throws { + init(from decoder: any Decoder) throws { let userInfoValue = decoder.userInfo[.testKey] as? String let container = try decoder.container(keyedBy: CodingKeys.self) diff --git a/Tests/GRDBTests/InflectionsTests.swift b/Tests/GRDBTests/InflectionsTests.swift index 5736b8463..12dba0560 100644 --- a/Tests/GRDBTests/InflectionsTests.swift +++ b/Tests/GRDBTests/InflectionsTests.swift @@ -252,7 +252,7 @@ struct InflectionTestCases: Decodable { } } - init(from decoder: Decoder) throws { + init(from decoder: any Decoder) throws { var testCases: [String: [(String, String)]] = [:] let container = try decoder.container(keyedBy: AnyCodingKey.self) for key in container.allKeys { diff --git a/Tests/GRDBTests/MutablePersistableRecordEncodableTests.swift b/Tests/GRDBTests/MutablePersistableRecordEncodableTests.swift index b6aa66fa8..542bfc9d9 100644 --- a/Tests/GRDBTests/MutablePersistableRecordEncodableTests.swift +++ b/Tests/GRDBTests/MutablePersistableRecordEncodableTests.swift @@ -38,7 +38,7 @@ extension MutablePersistableRecordEncodableTests { case value = "someColumn" } - func encode(to encoder: Encoder) throws { + func encode(to encoder: any Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(value + " (Encodable)", forKey: .value) } @@ -129,7 +129,7 @@ extension MutablePersistableRecordEncodableTests { struct Value : Encodable { let string: String - func encode(to encoder: Encoder) throws { + func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() try container.encode(string) } @@ -174,7 +174,7 @@ extension MutablePersistableRecordEncodableTests { struct NestedValue : Encodable { let string: String - func encode(to encoder: Encoder) throws { + func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() try container.encode(string) } @@ -183,7 +183,7 @@ extension MutablePersistableRecordEncodableTests { struct Value : Encodable { let nestedValue: NestedValue - func encode(to encoder: Encoder) throws { + func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() try container.encode(nestedValue) } @@ -281,7 +281,7 @@ extension MutablePersistableRecordEncodableTests { self.string = string } - func encode(to encoder: Encoder) throws { + func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() try container.encode(string + " (Encodable)") } @@ -576,7 +576,7 @@ extension MutablePersistableRecordEncodableTests { enum CodingKeys: String, CodingKey { case name, key, context } - func encode(to encoder: Encoder) throws { + func encode(to encoder: any Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(name, forKey: .name) try container.encodeIfPresent(encoder.codingPath.last?.stringValue, forKey: .key) @@ -587,7 +587,7 @@ extension MutablePersistableRecordEncodableTests { struct NestedSingle: Encodable { var name: String - func encode(to encoder: Encoder) throws { + func encode(to encoder: any Encoder) throws { var container = encoder.singleValueContainer() var value = name value += ",key:\(encoder.codingPath.last?.stringValue ?? "nil")" @@ -599,7 +599,7 @@ extension MutablePersistableRecordEncodableTests { struct NestedUnkeyed: Encodable { var name: String - func encode(to encoder: Encoder) throws { + func encode(to encoder: any Encoder) throws { var container = encoder.unkeyedContainer() try container.encode(name) if let key = encoder.codingPath.last?.stringValue { @@ -630,7 +630,7 @@ extension MutablePersistableRecordEncodableTests { case nestedKeyed, nestedSingle, nestedUnkeyed, key, context } - func encode(to encoder: Encoder) throws { + func encode(to encoder: any Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(nestedKeyed, forKey: .nestedKeyed) try container.encode(nestedSingle, forKey: .nestedSingle) @@ -668,7 +668,7 @@ extension MutablePersistableRecordEncodableTests { return encoder } - func encode(to encoder: Encoder) throws { + func encode(to encoder: any Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(nestedKeyed, forKey: .nestedKeyed) try container.encode(nestedSingle, forKey: .nestedSingle) @@ -798,7 +798,7 @@ extension MutablePersistableRecordEncodableTests { self.lastName = lastName } - func encode(to encoder: Encoder) throws { + func encode(to encoder: any Encoder) throws { let userInfoValue = encoder.userInfo[.testKey] as? String var container = encoder.container(keyedBy: CodingKeys.self) diff --git a/Tests/GRDBTests/SharedValueObservationTests.swift b/Tests/GRDBTests/SharedValueObservationTests.swift index ca53c61d9..a6a0aa7e4 100644 --- a/Tests/GRDBTests/SharedValueObservationTests.swift +++ b/Tests/GRDBTests/SharedValueObservationTests.swift @@ -523,7 +523,7 @@ class SharedValueObservationTests: GRDBTestCase { } let log = Log() - var fetchError: Error? = nil + var fetchError: (any Error)? = nil let publisher = ValueObservation .tracking { db -> Int in if let error = fetchError { throw error } @@ -579,7 +579,7 @@ class SharedValueObservationTests: GRDBTestCase { } let log = Log() - var fetchError: Error? = nil + var fetchError: (any Error)? = nil let publisher = ValueObservation .tracking { db -> Int in if let error = fetchError { throw error } diff --git a/Tests/GRDBTests/TransactionObserverTests.swift b/Tests/GRDBTests/TransactionObserverTests.swift index 730edc103..e22d470f3 100644 --- a/Tests/GRDBTests/TransactionObserverTests.swift +++ b/Tests/GRDBTests/TransactionObserverTests.swift @@ -4,7 +4,7 @@ import XCTest private class Observer : TransactionObserver { var lastCommittedEvents: [DatabaseEvent] = [] var events: [DatabaseEvent] = [] - var commitError: Error? + var commitError: (any Error)? var deinitBlock: (() -> ())? var didCommitBlock: ((Database) -> ())? var observesBlock: (DatabaseEventKind) -> Bool diff --git a/Tests/GRDBTests/ValueObservationRecorder.swift b/Tests/GRDBTests/ValueObservationRecorder.swift index fdc799f5a..0d17a4afd 100644 --- a/Tests/GRDBTests/ValueObservationRecorder.swift +++ b/Tests/GRDBTests/ValueObservationRecorder.swift @@ -14,7 +14,7 @@ public class ValueObservationRecorder { /// The recorder state private struct State { var values: [Value] - var error: Error? + var error: (any Error)? var recorderExpectation: RecorderExpectation? var cancellable: AnyDatabaseCancellable? } @@ -65,7 +65,7 @@ public class ValueObservationRecorder { } // Internal for testability. - func onError(_ error: Error) { + func onError(_ error: any Error) { return synchronized { if state.error != nil { // This is possible with ValueObservation, but not supported by ValueObservationRecorder @@ -140,7 +140,7 @@ public class ValueObservationRecorder { /// - returns: The value func value(_ value: ( _ values: [Value], - _ error: Error?, + _ error: (any Error)?, _ remainingValues: ArraySlice, _ consume: (_ count: Int) -> ()) throws -> T) rethrows -> T @@ -220,7 +220,7 @@ extension ValueObservation { public func record( in reader: some DatabaseReader, scheduling scheduler: some ValueObservationScheduler = .async(onQueue: .main), - onError: ((Error) -> Void)? = nil, + onError: ((any Error) -> Void)? = nil, onChange: ((Reducer.Value) -> Void)? = nil) -> ValueObservationRecorder where Reducer: ValueReducer @@ -805,7 +805,7 @@ extension ValueObservationExpectations { recorder.fulfillOnError(expectation) } - public func get() throws -> (values: [Value], error: Error) { + public func get() throws -> (values: [Value], error: any Error) { try recorder.value { (values, error, remainingValues, consume) in if let error { consume(remainingValues.count) diff --git a/Tests/GRDBTests/ValueObservationTests.swift b/Tests/GRDBTests/ValueObservationTests.swift index 31510bee7..fe3a3a1cd 100644 --- a/Tests/GRDBTests/ValueObservationTests.swift +++ b/Tests/GRDBTests/ValueObservationTests.swift @@ -37,7 +37,7 @@ class ValueObservationTests: GRDBTestCase { notificationExpectation.expectedFulfillmentCount = 4 notificationExpectation.isInverted = true - var nextError: Error? = nil // If not null, observation throws an error + var nextError: (any Error)? = nil // If not null, observation throws an error let observation = ValueObservation.trackingConstantRegion { _ = try Int.fetchOne($0, sql: "SELECT COUNT(*) FROM t") if let error = nextError { @@ -922,7 +922,7 @@ class ValueObservationTests: GRDBTestCase { let cancellationExpectation = expectation(description: "cancelled") // Launch a task that we'll cancel - let cancelledTask = Task { + let cancelledTask = Task { // Loops until cancelled let observation = ValueObservation.trackingConstantRegion(Table("t").fetchCount) let cancelledObservation = observation.handleEvents(didCancel: {