diff --git a/Examples/Relationships/RelationshipsExample/RelationshipsExample/FileCabinetDetailView.swift b/Examples/Relationships/RelationshipsExample/RelationshipsExample/FileCabinetDetailView.swift index 95e826f..09046ba 100644 --- a/Examples/Relationships/RelationshipsExample/RelationshipsExample/FileCabinetDetailView.swift +++ b/Examples/Relationships/RelationshipsExample/RelationshipsExample/FileCabinetDetailView.swift @@ -21,7 +21,7 @@ struct FileCabinetDetailView: View { ) } - @ViewBuilder @MainActor + @MainActor private func sidebar() -> some View { VStack { Text(viewModel.state.fileCabinet.id.uuidString) @@ -44,12 +44,12 @@ struct FileCabinetDetailView: View { } } - @ViewBuilder @MainActor + @MainActor private func content() -> some View { EmptyView() } - @ViewBuilder @MainActor + @MainActor private func detail() -> some View { EmptyView() } diff --git a/Examples/Relationships/RelationshipsExample/RelationshipsExample/FileCabinetsView.swift b/Examples/Relationships/RelationshipsExample/RelationshipsExample/FileCabinetsView.swift index 80f018f..5e9e04c 100644 --- a/Examples/Relationships/RelationshipsExample/RelationshipsExample/FileCabinetsView.swift +++ b/Examples/Relationships/RelationshipsExample/RelationshipsExample/FileCabinetsView.swift @@ -21,7 +21,7 @@ struct FileCabinetsView: View { ) } - @ViewBuilder @MainActor + @MainActor private func sidebar() -> some View { VStack { Button( @@ -55,7 +55,7 @@ struct FileCabinetsView: View { } } - @ViewBuilder @MainActor + @MainActor private func detail() -> some View { EmptyView() } diff --git a/Sources/CoreDataRepository/CoreDataBatchError.swift b/Sources/CoreDataRepository/CoreDataBatchError.swift index 6e5aa21..b74a16b 100644 --- a/Sources/CoreDataRepository/CoreDataBatchError.swift +++ b/Sources/CoreDataRepository/CoreDataBatchError.swift @@ -11,7 +11,7 @@ import Foundation /// Batch operations that do not use `NSBatch*Request` are not atomic. Some operations may succeed while others fail. If /// multiple errors are returned, it would /// be helpful if each error is associated with the input data for the operation. -public struct CoreDataBatchError: Error where T: Sendable { +public struct CoreDataBatchError: Error { /// The input data used for the batched operation. Usually an ``UnmanagedModel`` instance or URL encoded /// NSManagedObjectID. public let item: T diff --git a/Sources/CoreDataRepository/CoreDataRepository+Aggregate.swift b/Sources/CoreDataRepository/CoreDataRepository+Aggregate.swift index 08307f7..e3b4156 100644 --- a/Sources/CoreDataRepository/CoreDataRepository+Aggregate.swift +++ b/Sources/CoreDataRepository/CoreDataRepository+Aggregate.swift @@ -19,14 +19,14 @@ extension CoreDataRepository { } @inlinable - public func aggregate( + public func aggregate( function: AggregateFunction, predicate: NSPredicate, entityDesc: NSEntityDescription, attributeDesc: NSAttributeDescription, groupBy: NSAttributeDescription? = nil, as valueType: Value.Type - ) async -> Result where Value: Numeric, Value: Sendable { + ) async -> Result { switch function { case .count: await count(predicate: predicate, entityDesc: entityDesc, as: valueType) @@ -46,13 +46,13 @@ extension CoreDataRepository { /// Get the average of a managed object's numeric property for all instances that satisfy the predicate. @inlinable - public func average( + public func average( predicate: NSPredicate, entityDesc: NSEntityDescription, attributeDesc: NSAttributeDescription, groupBy: NSAttributeDescription? = nil, as _: Value.Type - ) async -> Result where Value: Numeric, Value: Sendable { + ) async -> Result { await Self.send( function: .average, context: Transaction.current?.context ?? context, @@ -65,13 +65,13 @@ extension CoreDataRepository { /// Subscribe to the average of a managed object's numeric property for all instances that satisfy the predicate. @inlinable - public func averageSubscription( + public func averageSubscription( predicate: NSPredicate, entityDesc: NSEntityDescription, attributeDesc: NSAttributeDescription, groupBy: NSAttributeDescription? = nil, as _: Value.Type - ) -> AsyncStream> where Value: Numeric, Value: Sendable { + ) -> AsyncStream> { AsyncStream { continuation in let subscription = AggregateSubscription( function: .average, @@ -91,13 +91,13 @@ extension CoreDataRepository { /// Subscribe to the average of a managed object's numeric property for all instances that satisfy the predicate. @inlinable - public func averageThrowingSubscription( + public func averageThrowingSubscription( predicate: NSPredicate, entityDesc: NSEntityDescription, attributeDesc: NSAttributeDescription, groupBy: NSAttributeDescription? = nil, as _: Value.Type - ) -> AsyncThrowingStream where Value: Numeric, Value: Sendable { + ) -> AsyncThrowingStream { AsyncThrowingStream { continuation in let subscription = AggregateThrowingSubscription( function: .average, @@ -119,11 +119,11 @@ extension CoreDataRepository { /// Get the count or quantity of managed object instances that satisfy the predicate. @inlinable - public func count( + public func count( predicate: NSPredicate, entityDesc: NSEntityDescription, as _: Value.Type - ) async -> Result where Value: Numeric, Value: Sendable { + ) async -> Result { await context.performInChild { scratchPad in do { let request = try NSFetchRequest @@ -140,11 +140,11 @@ extension CoreDataRepository { /// Subscribe to the count or quantity of managed object instances that satisfy the predicate. @inlinable - public func countSubscription( + public func countSubscription( predicate: NSPredicate, entityDesc: NSEntityDescription, as _: Value.Type - ) -> AsyncStream> where Value: Numeric, Value: Sendable { + ) -> AsyncStream> { AsyncStream { continuation in let subscription = CountSubscription( context: context.childContext(), @@ -161,11 +161,11 @@ extension CoreDataRepository { /// Subscribe to the count or quantity of managed object instances that satisfy the predicate. @inlinable - public func countThrowingSubscription( + public func countThrowingSubscription( predicate: NSPredicate, entityDesc: NSEntityDescription, as _: Value.Type - ) -> AsyncThrowingStream where Value: Numeric, Value: Sendable { + ) -> AsyncThrowingStream { AsyncThrowingStream { continuation in let subscription = CountThrowingSubscription( context: context.childContext(), @@ -184,13 +184,13 @@ extension CoreDataRepository { /// Get the max or maximum of a managed object's numeric property for all instances that satisfy the predicate. @inlinable - public func max( + public func max( predicate: NSPredicate, entityDesc: NSEntityDescription, attributeDesc: NSAttributeDescription, groupBy: NSAttributeDescription? = nil, as _: Value.Type - ) async -> Result where Value: Numeric, Value: Sendable { + ) async -> Result { await Self.send( function: .max, context: Transaction.current?.context ?? context, @@ -204,13 +204,13 @@ extension CoreDataRepository { /// Subscribe to the max or maximum of a managed object's numeric property for all instances that satisfy the /// predicate. @inlinable - public func maxSubscription( + public func maxSubscription( predicate: NSPredicate, entityDesc: NSEntityDescription, attributeDesc: NSAttributeDescription, groupBy: NSAttributeDescription? = nil, as _: Value.Type - ) -> AsyncStream> where Value: Numeric, Value: Sendable { + ) -> AsyncStream> { AsyncStream { continuation in let subscription = AggregateSubscription( function: .max, @@ -231,13 +231,13 @@ extension CoreDataRepository { /// Subscribe to the max or maximum of a managed object's numeric property for all instances that satisfy the /// predicate. @inlinable - public func maxThrowingSubscription( + public func maxThrowingSubscription( predicate: NSPredicate, entityDesc: NSEntityDescription, attributeDesc: NSAttributeDescription, groupBy: NSAttributeDescription? = nil, as _: Value.Type - ) -> AsyncThrowingStream where Value: Numeric, Value: Sendable { + ) -> AsyncThrowingStream { AsyncThrowingStream { continuation in let subscription = AggregateThrowingSubscription( function: .max, @@ -259,13 +259,13 @@ extension CoreDataRepository { /// Get the min or minimum of a managed object's numeric property for all instances that satisfy the predicate. @inlinable - public func min( + public func min( predicate: NSPredicate, entityDesc: NSEntityDescription, attributeDesc: NSAttributeDescription, groupBy: NSAttributeDescription? = nil, as _: Value.Type - ) async -> Result where Value: Numeric, Value: Sendable { + ) async -> Result { await Self.send( function: .min, context: Transaction.current?.context ?? context, @@ -279,13 +279,13 @@ extension CoreDataRepository { /// Subscribe to the min or minimum of a managed object's numeric property for all instances that satisfy the /// predicate. @inlinable - public func minSubscription( + public func minSubscription( predicate: NSPredicate, entityDesc: NSEntityDescription, attributeDesc: NSAttributeDescription, groupBy: NSAttributeDescription? = nil, as _: Value.Type - ) -> AsyncStream> where Value: Numeric, Value: Sendable { + ) -> AsyncStream> { AsyncStream { continuation in let subscription = AggregateSubscription( function: .min, @@ -306,13 +306,13 @@ extension CoreDataRepository { /// Subscribe to the min or minimum of a managed object's numeric property for all instances that satisfy the /// predicate. @inlinable - public func minThrowingSubscription( + public func minThrowingSubscription( predicate: NSPredicate, entityDesc: NSEntityDescription, attributeDesc: NSAttributeDescription, groupBy: NSAttributeDescription? = nil, as _: Value.Type - ) -> AsyncThrowingStream where Value: Numeric, Value: Sendable { + ) -> AsyncThrowingStream { AsyncThrowingStream { continuation in let subscription = AggregateThrowingSubscription( function: .min, @@ -334,13 +334,13 @@ extension CoreDataRepository { /// Get the sum of a managed object's numeric property for all instances that satisfy the predicate. @inlinable - public func sum( + public func sum( predicate: NSPredicate, entityDesc: NSEntityDescription, attributeDesc: NSAttributeDescription, groupBy: NSAttributeDescription? = nil, as _: Value.Type - ) async -> Result where Value: Numeric, Value: Sendable { + ) async -> Result { await Self.send( function: .sum, context: Transaction.current?.context ?? context, @@ -353,13 +353,13 @@ extension CoreDataRepository { /// Subscribe to the sum of a managed object's numeric property for all instances that satisfy the predicate. @inlinable - public func sumSubscription( + public func sumSubscription( predicate: NSPredicate, entityDesc: NSEntityDescription, attributeDesc: NSAttributeDescription, groupBy: NSAttributeDescription? = nil, as _: Value.Type - ) -> AsyncStream> where Value: Numeric, Value: Sendable { + ) -> AsyncStream> { AsyncStream { continuation in let subscription = AggregateSubscription( function: .sum, @@ -379,13 +379,13 @@ extension CoreDataRepository { /// Subscribe to the sum of a managed object's numeric property for all instances that satisfy the predicate. @inlinable - public func sumThrowingSubscription( + public func sumThrowingSubscription( predicate: NSPredicate, entityDesc: NSEntityDescription, attributeDesc: NSAttributeDescription, groupBy: NSAttributeDescription? = nil, as _: Value.Type - ) -> AsyncThrowingStream where Value: Numeric, Value: Sendable { + ) -> AsyncThrowingStream { AsyncThrowingStream { continuation in let subscription = AggregateThrowingSubscription( function: .sum, @@ -405,10 +405,10 @@ extension CoreDataRepository { // MARK: Internals - private static func aggregate( + private static func aggregate( context: NSManagedObjectContext, request: NSFetchRequest - ) throws -> Value where Value: Numeric, Value: Sendable { + ) throws -> Value { let result = try context.fetch(request) guard let value: Value = result.asAggregateValue() else { throw CoreDataError.fetchedObjectFailedToCastToExpectedType @@ -417,14 +417,14 @@ extension CoreDataRepository { } @usableFromInline - static func send( + static func send( function: AggregateFunction, context: NSManagedObjectContext, predicate: NSPredicate, entityDesc: NSEntityDescription, attributeDesc: NSAttributeDescription, groupBy: NSAttributeDescription? = nil - ) async -> Result where Value: Numeric, Value: Sendable { + ) async -> Result { guard entityDesc == attributeDesc.entity else { return .failure(.propertyDoesNotMatchEntity) } @@ -437,8 +437,7 @@ extension CoreDataRepository { groupBy: groupBy ) do { - let value: Value = try Self.aggregate(context: scratchPad, request: request) - return value + return try Self.aggregate(context: scratchPad, request: request) } catch let error as CocoaError { throw CoreDataError.cocoa(error) } catch { diff --git a/Sources/CoreDataRepository/CoreDataRepository+Create_Batch.swift b/Sources/CoreDataRepository/CoreDataRepository+Create_Batch.swift index a8ac057..da90583 100644 --- a/Sources/CoreDataRepository/CoreDataRepository+Create_Batch.swift +++ b/Sources/CoreDataRepository/CoreDataRepository+Create_Batch.swift @@ -41,8 +41,7 @@ extension CoreDataRepository { return await context.performInScratchPad(schedule: .enqueued) { [context] scratchPad in scratchPad.transactionAuthor = transactionAuthor let objects = try items.map { item in - let object = try item.asManagedModel(in: scratchPad) - return object + try item.asManagedModel(in: scratchPad) } try scratchPad.save() if notTransaction { diff --git a/Sources/CoreDataRepository/CoreDataRepository+Delete_Batch.swift b/Sources/CoreDataRepository/CoreDataRepository+Delete_Batch.swift index fe93894..969a9fa 100644 --- a/Sources/CoreDataRepository/CoreDataRepository+Delete_Batch.swift +++ b/Sources/CoreDataRepository/CoreDataRepository+Delete_Batch.swift @@ -53,10 +53,10 @@ extension CoreDataRepository { /// /// This operation is non-atomic. Each instance may succeed or fail individually. @inlinable - public func delete( + public func delete( _ items: [Model], transactionAuthor: String? = nil - ) async -> (success: [Model], failed: [CoreDataBatchError]) where Model: ReadableUnmanagedModel { + ) async -> (success: [Model], failed: [CoreDataBatchError]) { var successes = [Model]() var failures = [CoreDataBatchError]() for item in items { diff --git a/Sources/CoreDataRepository/CoreDataRepository+Fetch.swift b/Sources/CoreDataRepository/CoreDataRepository+Fetch.swift index c9a5b67..433c8a6 100644 --- a/Sources/CoreDataRepository/CoreDataRepository+Fetch.swift +++ b/Sources/CoreDataRepository/CoreDataRepository+Fetch.swift @@ -60,10 +60,10 @@ extension CoreDataRepository { /// Fetch items from the store with a ``NSFetchRequest`` and transform the results. @inlinable - public func fetch( + public func fetch( request: NSFetchRequest, operation: @escaping (_ results: [Managed]) throws -> Output - ) async -> Result where Managed: NSManagedObject { + ) async -> Result { let context = Transaction.current?.context ?? context return await context.performInChild { fetchContext in try operation(fetchContext.fetch(request)) diff --git a/Sources/CoreDataRepository/CoreDataRepository+Read.swift b/Sources/CoreDataRepository/CoreDataRepository+Read.swift index 75f439d..9204a15 100644 --- a/Sources/CoreDataRepository/CoreDataRepository+Read.swift +++ b/Sources/CoreDataRepository/CoreDataRepository+Read.swift @@ -21,10 +21,10 @@ extension CoreDataRepository { /// Read an instance from the store. @inlinable - public func read( + public func read( _ id: Model.UnmanagedId, of _: Model.Type - ) async -> Result where Model: IdentifiedUnmanagedModel { + ) async -> Result { let context = Transaction.current?.context ?? context return await context.performInChild(schedule: .enqueued) { readContext in let managed = try Model.readManaged(id: id, from: readContext) @@ -34,10 +34,10 @@ extension CoreDataRepository { /// Read an instance from the store. @inlinable - public func read( + public func read( _ managedId: NSManagedObjectID, of _: Model.Type - ) async -> Result where Model: FetchableUnmanagedModel { + ) async -> Result { let context = Transaction.current?.context ?? context return await context.performInChild(schedule: .enqueued) { readContext in let object = try readContext.notDeletedObject(for: managedId) @@ -48,10 +48,10 @@ extension CoreDataRepository { /// Read an instance from the store. @inlinable - public func read( + public func read( _ managedIdUrl: URL, of _: Model.Type - ) async -> Result where Model: FetchableUnmanagedModel { + ) async -> Result { let context = Transaction.current?.context ?? context return await context.performInChild(schedule: .enqueued) { readContext in let id = try readContext.objectId(from: managedIdUrl).get() diff --git a/Sources/CoreDataRepository/CoreDataRepository+Read_Batch.swift b/Sources/CoreDataRepository/CoreDataRepository+Read_Batch.swift index 67af1ef..e52cd5d 100644 --- a/Sources/CoreDataRepository/CoreDataRepository+Read_Batch.swift +++ b/Sources/CoreDataRepository/CoreDataRepository+Read_Batch.swift @@ -32,9 +32,9 @@ extension CoreDataRepository { /// /// This operation is non-atomic. Each instance may succeed or fail individually. @inlinable - public func read( + public func read( _ items: some Sequence - ) async -> (success: [Model], failed: [CoreDataBatchError]) where Model: ReadableUnmanagedModel { + ) async -> (success: [Model], failed: [CoreDataBatchError]) { var successes = [Model]() var failures = [CoreDataBatchError]() for item in items { diff --git a/Sources/CoreDataRepository/CoreDataRepository.swift b/Sources/CoreDataRepository/CoreDataRepository.swift index 2453f49..b9fbd38 100644 --- a/Sources/CoreDataRepository/CoreDataRepository.swift +++ b/Sources/CoreDataRepository/CoreDataRepository.swift @@ -55,11 +55,11 @@ public final class CoreDataRepository: @unchecked Sendable { /// - Returns: The result of the block execution. /// - Throws: ``CoreDataError`` if the transaction fails. @inlinable - public func withTransaction( + public func withTransaction( continuing existingTransaction: Transaction? = nil, transactionAuthor: String? = nil, _ block: (Transaction) async throws(E) -> T - ) async throws(CoreDataError) -> T where E: Error { + ) async throws(CoreDataError) -> T { let transaction = existingTransaction ?? Transaction(context: context.scratchPadContext()) let scratchPad = transaction.context return try await CoreDataError.catching { diff --git a/Sources/CoreDataRepository/Internal/AggregateSubscription.swift b/Sources/CoreDataRepository/Internal/AggregateSubscription.swift index 02aa2ee..5838677 100644 --- a/Sources/CoreDataRepository/Internal/AggregateSubscription.swift +++ b/Sources/CoreDataRepository/Internal/AggregateSubscription.swift @@ -9,9 +9,8 @@ import Foundation /// Subscription provider that sends updates when an aggregate fetch request changes @usableFromInline -final class AggregateSubscription: Subscription, - @unchecked Sendable where Value: Numeric, - Value: Sendable +final class AggregateSubscription: Subscription, + @unchecked Sendable { @usableFromInline override func fetch() { diff --git a/Sources/CoreDataRepository/Internal/AggregateThrowingSubscription.swift b/Sources/CoreDataRepository/Internal/AggregateThrowingSubscription.swift index d8deb4e..e60694e 100644 --- a/Sources/CoreDataRepository/Internal/AggregateThrowingSubscription.swift +++ b/Sources/CoreDataRepository/Internal/AggregateThrowingSubscription.swift @@ -9,9 +9,12 @@ import Foundation /// Subscription provider that sends updates when an aggregate fetch request changes @usableFromInline -final class AggregateThrowingSubscription: ThrowingSubscription, +final class AggregateThrowingSubscription: ThrowingSubscription< + Value, + NSDictionary, + NSManagedObject +>, @unchecked Sendable - where Value: Numeric, Value: Sendable { @usableFromInline override func fetch() { diff --git a/Sources/CoreDataRepository/Internal/ArrayOfNSDictionary+AggregateHelpers.swift b/Sources/CoreDataRepository/Internal/ArrayOfNSDictionary+AggregateHelpers.swift index b7f753e..451c220 100644 --- a/Sources/CoreDataRepository/Internal/ArrayOfNSDictionary+AggregateHelpers.swift +++ b/Sources/CoreDataRepository/Internal/ArrayOfNSDictionary+AggregateHelpers.swift @@ -8,7 +8,7 @@ import Foundation extension [NSDictionary] { /// Helper function to convert the result of a CoreData aggregate fetch to a numeric value - func asAggregateValue() -> Value? where Value: Numeric { + func asAggregateValue() -> Value? { ((self as? [[String: Value]]) ?? []).first?.values.first } } diff --git a/Sources/CoreDataRepository/Internal/CountSubscription.swift b/Sources/CoreDataRepository/Internal/CountSubscription.swift index 8cb67ef..085a865 100644 --- a/Sources/CoreDataRepository/Internal/CountSubscription.swift +++ b/Sources/CoreDataRepository/Internal/CountSubscription.swift @@ -9,9 +9,8 @@ import Foundation /// Subscription provider that sends updates when a count fetch request changes @usableFromInline -final class CountSubscription: Subscription, - @unchecked Sendable where Value: Numeric, - Value: Sendable +final class CountSubscription: Subscription, + @unchecked Sendable { @usableFromInline override func fetch() { diff --git a/Sources/CoreDataRepository/Internal/CountThrowingSubscription.swift b/Sources/CoreDataRepository/Internal/CountThrowingSubscription.swift index f466eff..6bc0a8e 100644 --- a/Sources/CoreDataRepository/Internal/CountThrowingSubscription.swift +++ b/Sources/CoreDataRepository/Internal/CountThrowingSubscription.swift @@ -9,9 +9,12 @@ import Foundation /// Subscription provider that sends updates when a count fetch request changes @usableFromInline -final class CountThrowingSubscription: ThrowingSubscription, +final class CountThrowingSubscription: ThrowingSubscription< + Value, + NSDictionary, + NSManagedObject +>, @unchecked Sendable - where Value: Numeric, Value: Sendable { @usableFromInline override func fetch() { diff --git a/Sources/CoreDataRepository/Internal/Subscription.swift b/Sources/CoreDataRepository/Internal/Subscription.swift index a6ac90d..8162505 100644 --- a/Sources/CoreDataRepository/Internal/Subscription.swift +++ b/Sources/CoreDataRepository/Internal/Subscription.swift @@ -10,10 +10,10 @@ import Foundation /// Base class for other subscriptions. @usableFromInline class Subscription< - Output, + Output: Sendable, RequestResult: NSFetchRequestResult, ControllerResult: NSFetchRequestResult ->: BaseSubscription, @unchecked Sendable where Output: Sendable { +>: BaseSubscription, @unchecked Sendable { let continuation: AsyncStream>.Continuation @usableFromInline diff --git a/Sources/CoreDataRepository/Internal/ThrowingSubscription.swift b/Sources/CoreDataRepository/Internal/ThrowingSubscription.swift index b95fe86..16734f2 100644 --- a/Sources/CoreDataRepository/Internal/ThrowingSubscription.swift +++ b/Sources/CoreDataRepository/Internal/ThrowingSubscription.swift @@ -10,10 +10,10 @@ import Foundation /// Base class for other subscriptions. @usableFromInline class ThrowingSubscription< - Output, + Output: Sendable, RequestResult: NSFetchRequestResult, ControllerResult: NSFetchRequestResult ->: BaseSubscription, @unchecked Sendable where Output: Sendable { +>: BaseSubscription, @unchecked Sendable { private let continuation: AsyncThrowingStream.Continuation @usableFromInline diff --git a/Sources/CoreDataRepository/NSManagedObject+Helpers.swift b/Sources/CoreDataRepository/NSManagedObject+Helpers.swift index 1cdb9e8..df5c938 100644 --- a/Sources/CoreDataRepository/NSManagedObject+Helpers.swift +++ b/Sources/CoreDataRepository/NSManagedObject+Helpers.swift @@ -10,7 +10,7 @@ import Foundation extension NSManagedObject { /// Helper function to handle casting ``NSManagedObject`` to a sub-class. @inlinable - public func asManagedModel() throws -> T where T: NSManagedObject { + public func asManagedModel() throws -> T { guard let repoManaged = self as? T else { throw CoreDataError.fetchedObjectFailedToCastToExpectedType } diff --git a/Tests/CoreDataRepositoryTests/CoreDataTestSuite.swift b/Tests/CoreDataRepositoryTests/CoreDataTestSuite.swift index f0e32fe..4702ed8 100644 --- a/Tests/CoreDataRepositoryTests/CoreDataTestSuite.swift +++ b/Tests/CoreDataRepositoryTests/CoreDataTestSuite.swift @@ -45,7 +45,7 @@ extension CoreDataTestSuite { // empty by default } - func verify(_ item: T) async throws where T: FetchableUnmanagedModel, T: Equatable { + func verify(_ item: T) async throws { repositoryContext.performAndWait { [repositoryContext] in var managed: T.ManagedModel? do { @@ -64,7 +64,7 @@ extension CoreDataTestSuite { } } - func verify(_ item: T) async throws where T: ReadableUnmanagedModel, T: Equatable { + func verify(_ item: T) async throws { try repositoryContext.performAndWait { [repositoryContext] in var _managed: T.ManagedModel? do { @@ -96,7 +96,7 @@ extension CoreDataTestSuite { } } - func verifyDoesNotExist(_ item: T) async throws where T: FetchableUnmanagedModel, T: Equatable { + func verifyDoesNotExist(_ item: T) async throws { repositoryContext.performAndWait { [repositoryContext] in var _managed: T.ManagedModel? do { @@ -111,7 +111,7 @@ extension CoreDataTestSuite { } } - func verifyDoesNotExist(_ item: T) async throws where T: ReadableUnmanagedModel, T: Equatable { + func verifyDoesNotExist(_ item: T) async throws { repositoryContext.performAndWait { [repositoryContext] in var _managed: T.ManagedModel? do { diff --git a/Tests/CoreDataRepositoryTests/CoreDataTestSuiteTests.swift b/Tests/CoreDataRepositoryTests/CoreDataTestSuiteTests.swift index 1f22af9..1bd95ea 100644 --- a/Tests/CoreDataRepositoryTests/CoreDataTestSuiteTests.swift +++ b/Tests/CoreDataRepositoryTests/CoreDataTestSuiteTests.swift @@ -32,7 +32,7 @@ extension CoreDataRepositoryTests { } @Test - func verify_Fetchable_Failure() async throws { + func verify_Fetchable_Failure() async { let modelType = FetchableModel_UuidId.self let _value = modelType.seeded(1) @@ -57,7 +57,7 @@ extension CoreDataRepositoryTests { } @Test - func verify_Readable_Failure() async throws { + func verify_Readable_Failure() async { let modelType = IdentifiableModel_UuidId.self let _value = modelType.seeded(1) @@ -135,7 +135,7 @@ extension CoreDataRepositoryTests { } @Test - func verifyHistory_Failure_NoHistory() async throws { + func verifyHistory_Failure_NoHistory() { let author: String = #function let date = Date.now diff --git a/Tests/CoreDataRepositoryTests/CustomTests.swift b/Tests/CoreDataRepositoryTests/CustomTests.swift index 8bee281..622f0e1 100644 --- a/Tests/CoreDataRepositoryTests/CustomTests.swift +++ b/Tests/CoreDataRepositoryTests/CustomTests.swift @@ -72,7 +72,7 @@ extension CoreDataRepositoryTests { let result: Result<(FetchableModel_UuidId, FetchableModel_UuidId), CoreDataError> = if inTransaction { await { do { - let result = try await repository.withTransaction(transactionAuthor: transactionAuthor) { _ in + return try await repository.withTransaction(transactionAuthor: transactionAuthor) { _ in await repository.custom { context, scratchPad in let object1 = modelType.ManagedModel(context: scratchPad) try _value1.updating(managed: object1) @@ -87,7 +87,6 @@ extension CoreDataRepositoryTests { return try (modelType.init(managed: object1), modelType.init(managed: object2)) } } - return result } catch { return .failure(error as! CoreDataError) } diff --git a/Tests/CoreDataRepositoryTests/DeleteTests.swift b/Tests/CoreDataRepositoryTests/DeleteTests.swift index f670f22..9449a6a 100644 --- a/Tests/CoreDataRepositoryTests/DeleteTests.swift +++ b/Tests/CoreDataRepositoryTests/DeleteTests.swift @@ -37,7 +37,7 @@ extension CoreDataRepositoryTests { } @Test - func delete_Identifiable_Failure() async throws { + func delete_Identifiable_Failure() async { let modelType = IdentifiableModel_UuidId.self let _value = modelType.seeded(1) let result = await repository @@ -105,7 +105,7 @@ extension CoreDataRepositoryTests { } @Test - func delete_ManagedIdReferencable_NoManagedId_Failure() async throws { + func delete_ManagedIdReferencable_NoManagedId_Failure() async { let modelType = ManagedIdModel_UuidId.self let _value = modelType.seeded(1) @@ -226,7 +226,7 @@ extension CoreDataRepositoryTests { } @Test - func delete_ManagedIdUrlReferencable_NoManagedIdUrl_Failure() async throws { + func delete_ManagedIdUrlReferencable_NoManagedIdUrl_Failure() async { let modelType = ManagedIdUrlModel_UuidId.self let _value = modelType.seeded(1)