File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
Sources/ManagedModels/PersistentModel Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,15 @@ public extension PersistentModel {
3131 where T: Codable & CoreDataPrimitiveValue & AnyOptional
3232 {
3333 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+ }
3543 }
3644 @inlinable
3745 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 {
6767 XCTAssertEqual ( relationship. isOrdered, copiedRelationship. isOrdered)
6868 XCTAssertEqual ( relationship. maxCount, copiedRelationship. maxCount)
6969 }
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+ }
7086}
You can’t perform that action at this time.
0 commit comments