diff --git a/Sources/ManagedModels/PersistentModel/PersistentModel+KVC.swift b/Sources/ManagedModels/PersistentModel/PersistentModel+KVC.swift index 9224b1d..a5bf94b 100644 --- a/Sources/ManagedModels/PersistentModel/PersistentModel+KVC.swift +++ b/Sources/ManagedModels/PersistentModel/PersistentModel+KVC.swift @@ -52,7 +52,7 @@ public extension PersistentModel { // MARK: - Transformable public extension PersistentModel { - + @inlinable func setTransformableValue(forKey key: String, to value: Any) { willChangeValue(forKey: key); defer { didChangeValue(forKey: key) } @@ -64,6 +64,23 @@ public extension PersistentModel { willAccessValue(forKey: key); defer { didAccessValue(forKey: key) } return primitiveValue(forKey: key) as! T } + + @inlinable + func setTransformableValue(forKey key: String, to value: Any?) { + willChangeValue(forKey: key); defer { didChangeValue(forKey: key) } + setPrimitiveValue(value, forKey: key) + } + + @inlinable + func getTransformableValue(forKey key: String) -> T + where T: AnyOptional + { + willAccessValue(forKey: key); defer { didAccessValue(forKey: key) } + guard let value = primitiveValue(forKey: key) else { + return .noneValue + } + return (value as? T) ?? .noneValue + } }