Skip to content

Commit

Permalink
Add accessors for optional overloads
Browse files Browse the repository at this point in the history
Avoid a warning and double wrapping.
  • Loading branch information
helje5 committed Feb 16, 2024
1 parent 5457203 commit 6c1ef00
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion Sources/ManagedModels/PersistentModel/PersistentModel+KVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand All @@ -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<T>(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
}
}


Expand Down

0 comments on commit 6c1ef00

Please sign in to comment.