Skip to content

Commit

Permalink
Fix issue #22, optional handling
Browse files Browse the repository at this point in the history
Finally able to understand the issue. The typed
optional .none is properly bridged to NSNull,
but the coercion isn't even necessary.
  • Loading branch information
helje5 committed Oct 7, 2023
1 parent 86720f5 commit 768502f
Showing 1 changed file with 9 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

0 comments on commit 768502f

Please sign in to comment.