Skip to content

Commit 7b8fe9a

Browse files
committed
Trying to fix issue with Codable transformation to and from base type T
1 parent 4d04acc commit 7b8fe9a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Sources/ManagedModels/SchemaCompatibility/CodableBox.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ final class CodableBox<T: Codable>: NSObject, NSCopying {
6666

6767
override func transformedValue(_ value: Any?) -> Any? {
6868
// value is the box
69-
guard let value else { return nil }
69+
guard var value else { return nil }
70+
if let baseTyped = value as? T {
71+
value = CodableBox<T>(baseTyped)
72+
}
7073
guard let typed = value as? CodableBox<T> else {
7174
assertionFailure("Value to be transformed is not the box? \(value)")
7275
return nil
@@ -77,7 +80,7 @@ final class CodableBox<T: Codable>: NSObject, NSCopying {
7780
override func reverseTransformedValue(_ value: Any?) -> Any? {
7881
guard let value else { return nil }
7982
guard let data = value as? Data else { return nil }
80-
return CodableBox<T>(data: data)
83+
return CodableBox<T>(data: data)?.value
8184
}
8285
}
8386
}

0 commit comments

Comments
 (0)