File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -70,6 +70,9 @@ public protocol FetchableUnmanagedModel: Sendable {
7070
7171 /// A description of the context from where an error is thrown
7272 var errorDescription : String { get }
73+
74+ /// A description of the context from where an error is thrown but there is no instance `self` to use
75+ static var errorDescription : String { get }
7376}
7477
7578extension FetchableUnmanagedModel {
@@ -85,4 +88,9 @@ extension FetchableUnmanagedModel {
8588 public var errorDescription : String {
8689 " \( Self . self) "
8790 }
91+
92+ @inlinable
93+ public static var errorDescription : String {
94+ " \( Self . self) "
95+ }
8896}
Original file line number Diff line number Diff line change @@ -32,12 +32,22 @@ extension IdentifiedUnmanagedModel {
3232 let fetchResult = try context. fetch ( request)
3333 guard let managed = fetchResult. first, fetchResult. count == 1 else {
3434 throw CoreDataError
35- . noMatchFoundWhenReadingItem ( description: " \( Self . self) -- id: \( errorDescription ( for: id) ) " )
35+ . noMatchFoundWhenReadingItem (
36+ description: " \( Self . errorDescription) -- id: \( errorDescription ( for: id) ) "
37+ )
3638 }
3739 guard !managed. isDeleted else {
3840 throw CoreDataError
39- . fetchedObjectIsFlaggedAsDeleted ( description: " \( Self . self) -- id: \( errorDescription ( for: id) ) " )
41+ . fetchedObjectIsFlaggedAsDeleted (
42+ description: " \( Self . errorDescription) -- id: \( errorDescription ( for: id) ) "
43+ )
4044 }
4145 return managed
4246 }
4347}
48+
49+ extension IdentifiedUnmanagedModel where UnmanagedId: CustomStringConvertible {
50+ public static func errorDescription( for unmanagedId: UnmanagedId ) -> String {
51+ unmanagedId. description
52+ }
53+ }
Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ extension ReadableUnmanagedModel where Self: ManagedIdReferencable {
8080 @inlinable
8181 public func readManaged( from context: NSManagedObjectContext ) throws -> ManagedModel {
8282 guard let managedId else {
83- throw CoreDataError . noObjectIdOnItem ( description: " \( Self . self ) " )
83+ throw CoreDataError . noObjectIdOnItem ( description: errorDescription )
8484 }
8585 return try context. notDeletedObject ( for: managedId) . asManagedModel ( )
8686 }
@@ -90,7 +90,7 @@ extension ReadableUnmanagedModel where Self: ManagedIdUrlReferencable {
9090 @inlinable
9191 public func readManaged( from context: NSManagedObjectContext ) throws -> ManagedModel {
9292 guard let managedIdUrl else {
93- throw CoreDataError . noUrlOnItemToMapToObjectId ( description: " \( Self . self ) " )
93+ throw CoreDataError . noUrlOnItemToMapToObjectId ( description: errorDescription )
9494 }
9595 let managedId = try context. objectId ( from: managedIdUrl) . get ( )
9696 return try context. notDeletedObject ( for: managedId) . asManagedModel ( )
Original file line number Diff line number Diff line change @@ -105,10 +105,6 @@ extension IdentifiableModel_IntId: IdentifiedUnmanagedModel {
105105 }
106106
107107 package nonisolated ( unsafe) static let unmanagedIdExpression = NSExpression ( forKeyPath: \ManagedModel_IntId . id)
108-
109- package static func errorDescription( for unmanagedId: Int ) -> String {
110- unmanagedId. description
111- }
112108}
113109
114110extension IdentifiableModel_IntId : WritableUnmanagedModel {
Original file line number Diff line number Diff line change @@ -105,10 +105,6 @@ extension IdentifiableModel_UuidId: IdentifiedUnmanagedModel {
105105 }
106106
107107 package nonisolated ( unsafe) static let unmanagedIdExpression = NSExpression ( forKeyPath: \ManagedModel_UuidId . id)
108-
109- package static func errorDescription( for unmanagedId: UUID ) -> String {
110- unmanagedId. uuidString
111- }
112108}
113109
114110extension IdentifiableModel_UuidId : WritableUnmanagedModel {
You can’t perform that action at this time.
0 commit comments