Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/CoreDataRepository/IdentifiedUnmanagedModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion Sources/Internal/ModelsWithIntId/IdentifiableModel_Int.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ 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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ 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)
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/CoreDataRepositoryTests/BatchRequestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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()
}
Expand Down