File tree 2 files changed +25
-1
lines changed
Sources/ManagedModels/PersistentModel
2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,15 @@ public extension PersistentModel {
31
31
where T: Codable & CoreDataPrimitiveValue & AnyOptional
32
32
{
33
33
willChangeValue ( forKey: key) ; defer { didChangeValue ( forKey: key) }
34
- setPrimitiveValue ( value, forKey: key)
34
+
35
+ // While `nil` is properly bridged to `NSNull`, this is still necessary
36
+ // because `T` is the Optional structure, NOT the value type. I think :-)
37
+ if value. isSome {
38
+ setPrimitiveValue ( value. value, forKey: key)
39
+ }
40
+ else {
41
+ setPrimitiveValue ( nil , forKey: key)
42
+ }
35
43
}
36
44
@inlinable
37
45
func getValue< T> ( forKey key: String ) -> T
Original file line number Diff line number Diff line change @@ -67,4 +67,20 @@ final class CoreDataAssumptionsTests: XCTestCase {
67
67
XCTAssertEqual ( relationship. isOrdered, copiedRelationship. isOrdered)
68
68
XCTAssertEqual ( relationship. maxCount, copiedRelationship. maxCount)
69
69
}
70
+
71
+
72
+ func testAttributeValueClassIsNotEmpty( ) throws {
73
+ do {
74
+ let attribute = NSAttributeDescription ( )
75
+ attribute. name = " Hello "
76
+ attribute. attributeType = . stringAttributeType
77
+ XCTAssertEqual ( attribute. attributeValueClassName, " NSString " )
78
+ }
79
+ do {
80
+ let attribute = NSAttributeDescription ( )
81
+ attribute. name = " Hello "
82
+ attribute. attributeType = . integer16AttributeType
83
+ XCTAssertEqual ( attribute. attributeValueClassName, " NSNumber " )
84
+ }
85
+ }
70
86
}
You can’t perform that action at this time.
0 commit comments