Skip to content

Commit 40e531d

Browse files
committed
Merge branch 'develop'
2 parents 1530d28 + 768502f commit 40e531d

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

Sources/ManagedModels/PersistentModel/PersistentModel+KVC.swift

+9-1
Original file line numberDiff line numberDiff 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

Tests/ManagedModelTests/CoreDataAssumptionsTests.swift

+16
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)