diff --git a/Sources/ManagedModels/SchemaCompatibility/CodableBox.swift b/Sources/ManagedModels/SchemaCompatibility/CodableBox.swift index 7a42d4b..fb45a73 100644 --- a/Sources/ManagedModels/SchemaCompatibility/CodableBox.swift +++ b/Sources/ManagedModels/SchemaCompatibility/CodableBox.swift @@ -66,7 +66,10 @@ final class CodableBox: NSObject, NSCopying { override func transformedValue(_ value: Any?) -> Any? { // value is the box - guard let value else { return nil } + guard var value else { return nil } + if let baseTyped = value as? T { + value = CodableBox(baseTyped) + } guard let typed = value as? CodableBox else { assertionFailure("Value to be transformed is not the box? \(value)") return nil @@ -77,7 +80,7 @@ final class CodableBox: NSObject, NSCopying { override func reverseTransformedValue(_ value: Any?) -> Any? { guard let value else { return nil } guard let data = value as? Data else { return nil } - return CodableBox(data: data) + return CodableBox(data: data)?.value } } }