Hello friends , this is my first time writing on the Swift Forums. I was following this from a long time.
First time I am working on KeyPath. I have to set the values of the generic properties using KeyPath. Created a protocol which has the set method to set the new values.
protocol TypedKeyPath {
func set<V>(of entity: Entity, to newValue: V)
}
extension ReferenceWritableKeyPath : TypedKeyPath {
func set<V>(of entity: Entity, to newValue: V) {
entity[keyPath: self] = newValue // error: Use of unresolved identifier 'entity'
}
}
In my top class of my source are of type TypedKeyPath, I will set the value of my source using this method.
func setValue(of entity: Entity) {
for (keypath, source) in sourceMap {
let value = source.getValue()
keypath?.set(of: entity, to: value)
}
Problem is I have a compiler error. I am unable to solve this .