From e58004242d0272bd8cc5cd5c755873a144fe2de8 Mon Sep 17 00:00:00 2001 From: Andrew Roan Date: Wed, 8 Oct 2025 19:06:15 -0500 Subject: [PATCH 1/2] Remove unmanagedIdAccessor in favor of unmanagedId property in IdentifiedUnmanagedModel feature/add-unmanagedId-property --- Sources/CoreDataRepository/IdentifiedUnmanagedModel.swift | 4 ++-- Sources/Internal/ModelsWithIntId/IdentifiableModel_Int.swift | 4 +++- .../Internal/ModelsWithUuidId/IdentifiableModel_Uuid.swift | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Sources/CoreDataRepository/IdentifiedUnmanagedModel.swift b/Sources/CoreDataRepository/IdentifiedUnmanagedModel.swift index dece4d2..7e22ae2 100644 --- a/Sources/CoreDataRepository/IdentifiedUnmanagedModel.swift +++ b/Sources/CoreDataRepository/IdentifiedUnmanagedModel.swift @@ -8,14 +8,14 @@ import CoreData public protocol IdentifiedUnmanagedModel: ReadableUnmanagedModel { associatedtype UnmanagedId: Equatable - static var unmanagedIdAccessor: (Self) -> UnmanagedId { get } + var unmanagedId: UnmanagedId { get } static var managedIdExpression: NSExpression { get } } extension IdentifiedUnmanagedModel { @inlinable public func readManaged(from context: NSManagedObjectContext) throws -> ManagedModel { - try Self.readManaged(id: Self.unmanagedIdAccessor(self), from: context) + try Self.readManaged(id: unmanagedId, from: context) } @inlinable diff --git a/Sources/Internal/ModelsWithIntId/IdentifiableModel_Int.swift b/Sources/Internal/ModelsWithIntId/IdentifiableModel_Int.swift index 9d7cc85..3349268 100644 --- a/Sources/Internal/ModelsWithIntId/IdentifiableModel_Int.swift +++ b/Sources/Internal/ModelsWithIntId/IdentifiableModel_Int.swift @@ -100,7 +100,9 @@ extension IdentifiableModel_IntId: IdentifiedUnmanagedModel { } @inlinable - package static var unmanagedIdAccessor: (IdentifiableModel_IntId) -> Int { \.id } + package var unmanagedId: Int { + id + } package nonisolated(unsafe) static let managedIdExpression = NSExpression(forKeyPath: \ManagedModel_IntId.id) } diff --git a/Sources/Internal/ModelsWithUuidId/IdentifiableModel_Uuid.swift b/Sources/Internal/ModelsWithUuidId/IdentifiableModel_Uuid.swift index 853038a..c0c54ec 100644 --- a/Sources/Internal/ModelsWithUuidId/IdentifiableModel_Uuid.swift +++ b/Sources/Internal/ModelsWithUuidId/IdentifiableModel_Uuid.swift @@ -100,7 +100,9 @@ extension IdentifiableModel_UuidId: IdentifiedUnmanagedModel { } @inlinable - package static var unmanagedIdAccessor: (IdentifiableModel_UuidId) -> UUID { \.id } + package var unmanagedId: UUID { + id + } package nonisolated(unsafe) static let managedIdExpression = NSExpression(forKeyPath: \ManagedModel_UuidId.id) } From 45c70e0417866aa90d4a1f1109d217751b4c2c95 Mon Sep 17 00:00:00 2001 From: Andrew Roan Date: Thu, 9 Oct 2025 15:58:04 -0500 Subject: [PATCH 2/2] Run swiftformat feature/add-unmanagedId-property --- Sources/Internal/ModelsWithIntId/IdentifiableModel_Int.swift | 1 + .../Internal/ModelsWithUuidId/IdentifiableModel_Uuid.swift | 1 + Tests/CoreDataRepositoryTests/BatchRequestTests.swift | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/Internal/ModelsWithIntId/IdentifiableModel_Int.swift b/Sources/Internal/ModelsWithIntId/IdentifiableModel_Int.swift index 3349268..110036e 100644 --- a/Sources/Internal/ModelsWithIntId/IdentifiableModel_Int.swift +++ b/Sources/Internal/ModelsWithIntId/IdentifiableModel_Int.swift @@ -103,6 +103,7 @@ extension IdentifiableModel_IntId: IdentifiedUnmanagedModel { package var unmanagedId: Int { id } + package nonisolated(unsafe) static let managedIdExpression = NSExpression(forKeyPath: \ManagedModel_IntId.id) } diff --git a/Sources/Internal/ModelsWithUuidId/IdentifiableModel_Uuid.swift b/Sources/Internal/ModelsWithUuidId/IdentifiableModel_Uuid.swift index c0c54ec..3e928ba 100644 --- a/Sources/Internal/ModelsWithUuidId/IdentifiableModel_Uuid.swift +++ b/Sources/Internal/ModelsWithUuidId/IdentifiableModel_Uuid.swift @@ -103,6 +103,7 @@ extension IdentifiableModel_UuidId: IdentifiedUnmanagedModel { package var unmanagedId: UUID { id } + package nonisolated(unsafe) static let managedIdExpression = NSExpression(forKeyPath: \ManagedModel_UuidId.id) } diff --git a/Tests/CoreDataRepositoryTests/BatchRequestTests.swift b/Tests/CoreDataRepositoryTests/BatchRequestTests.swift index cba3de5..e5e7c6c 100644 --- a/Tests/CoreDataRepositoryTests/BatchRequestTests.swift +++ b/Tests/CoreDataRepositoryTests/BatchRequestTests.swift @@ -159,7 +159,7 @@ extension CoreDataRepositoryTests { let count = try repositoryContext.count(for: fetchRequest) expectNoDifference(count, 0, "Count of objects in CoreData should be zero at the start of each test.") - let _ = try values + _ = try values .map(mapDictToManagedModel(_:)) try repositoryContext.save() } @@ -207,7 +207,7 @@ extension CoreDataRepositoryTests { let count = try repositoryContext.count(for: fetchRequest) expectNoDifference(count, 0, "Count of objects in CoreData should be zero at the start of each test.") - let _ = try values + _ = try values .map(mapDictToManagedModel(_:)) try repositoryContext.save() }