mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-11 21:11:58 +01:00
add Field.Relationship dynamicMemberLookups
This commit is contained in:
@@ -397,6 +397,24 @@ extension ObjectPublisher where O: CoreStoreObject {
|
||||
return FieldContainer<OBase>.Computed<V>.read(field: object[keyPath: member], for: rawObject) as! V?
|
||||
}
|
||||
|
||||
/**
|
||||
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? {
|
||||
|
||||
guard
|
||||
let object = self.object,
|
||||
let rawObject = object.rawObject,
|
||||
let value = FieldContainer<OBase>.Relationship<V>.read(field: object[keyPath: member], for: rawObject) as! V?
|
||||
else {
|
||||
|
||||
return nil
|
||||
}
|
||||
let nativeValue = V.cs_toNativeType(from: value)
|
||||
let snapshotValue = V.cs_valueForSnapshot(from: nativeValue)
|
||||
return V.cs_toPublishedType(from: snapshotValue, in: self.context)
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the value for the property identified by a given key.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user