add Field.Relationship dynamicMemberLookups

This commit is contained in:
John Estropia
2020-02-05 11:03:57 +09:00
parent e9c3312612
commit c20fe4ac17
3 changed files with 79 additions and 0 deletions

View File

@@ -209,6 +209,25 @@ extension ObjectSnapshot where O: CoreStoreObject {
}
}
/**
Returns the value for the property identified by a given key.
*/
public subscript<OBase, V>(dynamicMember member: KeyPath<O, FieldContainer<OBase>.Relationship<V>>) -> V.PublishedType {
get {
let key = String(keyPath: member)
let context = self.context
let snapshotValue = self.values[key] as! V.SnapshotValueType
return V.cs_toPublishedType(from: snapshotValue, in: context)
}
set {
let key = String(keyPath: member)
self.values[key] = V.cs_toSnapshotType(from: newValue)
}
}
/**
Returns the value for the property identified by a given key.
*/