Skip to content

Commit 6a7d80f

Browse files
authored
Merge pull request #39 from roanutil/feature/add-unmanagedId-property
Remove unmanagedIdAccessor in favor of unmanagedId property in IdentifiedUnmanagedModel
2 parents da539b7 + 45c70e0 commit 6a7d80f

4 files changed

Lines changed: 12 additions & 6 deletions

File tree

Sources/CoreDataRepository/IdentifiedUnmanagedModel.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import CoreData
88

99
public protocol IdentifiedUnmanagedModel: ReadableUnmanagedModel {
1010
associatedtype UnmanagedId: Equatable
11-
static var unmanagedIdAccessor: (Self) -> UnmanagedId { get }
11+
var unmanagedId: UnmanagedId { get }
1212
static var managedIdExpression: NSExpression { get }
1313
}
1414

1515
extension IdentifiedUnmanagedModel {
1616
@inlinable
1717
public func readManaged(from context: NSManagedObjectContext) throws -> ManagedModel {
18-
try Self.readManaged(id: Self.unmanagedIdAccessor(self), from: context)
18+
try Self.readManaged(id: unmanagedId, from: context)
1919
}
2020

2121
@inlinable

Sources/Internal/ModelsWithIntId/IdentifiableModel_Int.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ extension IdentifiableModel_IntId: IdentifiedUnmanagedModel {
100100
}
101101

102102
@inlinable
103-
package static var unmanagedIdAccessor: (IdentifiableModel_IntId) -> Int { \.id }
103+
package var unmanagedId: Int {
104+
id
105+
}
106+
104107
package nonisolated(unsafe) static let managedIdExpression = NSExpression(forKeyPath: \ManagedModel_IntId.id)
105108
}
106109

Sources/Internal/ModelsWithUuidId/IdentifiableModel_Uuid.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ extension IdentifiableModel_UuidId: IdentifiedUnmanagedModel {
100100
}
101101

102102
@inlinable
103-
package static var unmanagedIdAccessor: (IdentifiableModel_UuidId) -> UUID { \.id }
103+
package var unmanagedId: UUID {
104+
id
105+
}
106+
104107
package nonisolated(unsafe) static let managedIdExpression = NSExpression(forKeyPath: \ManagedModel_UuidId.id)
105108
}
106109

Tests/CoreDataRepositoryTests/BatchRequestTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ extension CoreDataRepositoryTests {
159159
let count = try repositoryContext.count(for: fetchRequest)
160160
expectNoDifference(count, 0, "Count of objects in CoreData should be zero at the start of each test.")
161161

162-
let _ = try values
162+
_ = try values
163163
.map(mapDictToManagedModel(_:))
164164
try repositoryContext.save()
165165
}
@@ -207,7 +207,7 @@ extension CoreDataRepositoryTests {
207207
let count = try repositoryContext.count(for: fetchRequest)
208208
expectNoDifference(count, 0, "Count of objects in CoreData should be zero at the start of each test.")
209209

210-
let _ = try values
210+
_ = try values
211211
.map(mapDictToManagedModel(_:))
212212
try repositoryContext.save()
213213
}

0 commit comments

Comments
 (0)