Skip to content

Commit 6c1ef00

Browse files
committed
Add accessors for optional overloads
Avoid a warning and double wrapping.
1 parent 5457203 commit 6c1ef00

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Sources/ManagedModels/PersistentModel/PersistentModel+KVC.swift

+18-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public extension PersistentModel {
5252

5353
// MARK: - Transformable
5454
public extension PersistentModel {
55-
55+
5656
@inlinable
5757
func setTransformableValue(forKey key: String, to value: Any) {
5858
willChangeValue(forKey: key); defer { didChangeValue(forKey: key) }
@@ -64,6 +64,23 @@ public extension PersistentModel {
6464
willAccessValue(forKey: key); defer { didAccessValue(forKey: key) }
6565
return primitiveValue(forKey: key) as! T
6666
}
67+
68+
@inlinable
69+
func setTransformableValue(forKey key: String, to value: Any?) {
70+
willChangeValue(forKey: key); defer { didChangeValue(forKey: key) }
71+
setPrimitiveValue(value, forKey: key)
72+
}
73+
74+
@inlinable
75+
func getTransformableValue<T>(forKey key: String) -> T
76+
where T: AnyOptional
77+
{
78+
willAccessValue(forKey: key); defer { didAccessValue(forKey: key) }
79+
guard let value = primitiveValue(forKey: key) else {
80+
return .noneValue
81+
}
82+
return (value as? T) ?? .noneValue
83+
}
6784
}
6885

6986

0 commit comments

Comments
 (0)