File tree 3 files changed +27
-2
lines changed
Sources/ManagedModels/SchemaCompatibility
3 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -32,8 +32,8 @@ extension CoreData.NSAttributeDescription: SchemaProperty {
32
32
if let baseType = attributeType. swiftBaseType ( isOptional: isOptional) {
33
33
return baseType
34
34
}
35
- guard let attributeValueClassName else { return Any . self }
36
- return NSClassFromString ( attributeValueClassName) ?? Any . self
35
+ guard let attributeValueClassName else { return isOptional ? Any ? . self : Any . self }
36
+ return NSClassFromString ( attributeValueClassName) ?? ( isOptional ? Any ? . self : Any . self )
37
37
}
38
38
set {
39
39
// Note: This needs to match up w/ PersistentModel+KVC.
Original file line number Diff line number Diff line change @@ -69,4 +69,28 @@ final class CodablePropertiesTests: XCTestCase {
69
69
XCTAssertNotNil ( attribute. valueTransformerName)
70
70
XCTAssertEqual ( attribute. valueTransformerName, transformerName. rawValue)
71
71
}
72
+
73
+ func testOptionalCodablePropertyEntity( ) throws {
74
+ let entity = try XCTUnwrap (
75
+ container? . managedObjectModel. entitiesByName [ " StoredAccess " ]
76
+ )
77
+
78
+ // Creating the entity should have registered the transformer for the
79
+ // CodableBox.
80
+ let transformerName = try XCTUnwrap (
81
+ ValueTransformer . valueTransformerNames ( ) . first ( where: {
82
+ $0. rawValue. range ( of: " CodableTransformerGSqVOO17ManagedModelTests8 " )
83
+ != nil
84
+ } )
85
+ )
86
+ let transformer = try XCTUnwrap ( ValueTransformer ( forName: transformerName) )
87
+ _ = transformer // to clear unused-wraning
88
+
89
+ let attribute = try XCTUnwrap ( entity. attributesByName [ " optionalSip " ] )
90
+ XCTAssertEqual ( attribute. name, " optionalSip " )
91
+ XCTAssertTrue ( attribute. valueType == Any ? . self)
92
+ // Fixtures.CodablePropertiesSchema.AccessSIP?.self)
93
+ XCTAssertNotNil ( attribute. valueTransformerName)
94
+ XCTAssertEqual ( attribute. valueTransformerName, transformerName. rawValue)
95
+ }
72
96
}
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ extension Fixtures {
20
20
var token : String
21
21
var expires : Date
22
22
var sip : AccessSIP
23
+ var optionalSip : AccessSIP ?
23
24
}
24
25
25
26
struct AccessSIP : Codable {
You can’t perform that action at this time.
0 commit comments