Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
helje5 committed Oct 7, 2023
2 parents 1530d28 + 768502f commit 40e531d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Sources/ManagedModels/PersistentModel/PersistentModel+KVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ public extension PersistentModel {
where T: Codable & CoreDataPrimitiveValue & AnyOptional
{
willChangeValue(forKey: key); defer { didChangeValue(forKey: key) }
setPrimitiveValue(value, forKey: key)

// While `nil` is properly bridged to `NSNull`, this is still necessary
// because `T` is the Optional structure, NOT the value type. I think :-)
if value.isSome {
setPrimitiveValue(value.value, forKey: key)
}
else {
setPrimitiveValue(nil, forKey: key)
}
}
@inlinable
func getValue<T>(forKey key: String) -> T
Expand Down
16 changes: 16 additions & 0 deletions Tests/ManagedModelTests/CoreDataAssumptionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,20 @@ final class CoreDataAssumptionsTests: XCTestCase {
XCTAssertEqual(relationship.isOrdered, copiedRelationship.isOrdered)
XCTAssertEqual(relationship.maxCount, copiedRelationship.maxCount)
}


func testAttributeValueClassIsNotEmpty() throws {
do {
let attribute = NSAttributeDescription()
attribute.name = "Hello"
attribute.attributeType = .stringAttributeType
XCTAssertEqual(attribute.attributeValueClassName, "NSString")
}
do {
let attribute = NSAttributeDescription()
attribute.name = "Hello"
attribute.attributeType = .integer16AttributeType
XCTAssertEqual(attribute.attributeValueClassName, "NSNumber")
}
}
}

0 comments on commit 40e531d

Please sign in to comment.