prototype new Fields as propertyWrappers (Swift 5.2 above only)

This commit is contained in:
John Estropia
2020-01-15 18:29:58 +09:00
parent 5e37ee4566
commit 43f61359da
33 changed files with 1796 additions and 337 deletions

View File

@@ -367,6 +367,36 @@ extension ObjectPublisher where O: CoreStoreObject {
// MARK: Public
/**
Returns the value for the property identified by a given key.
*/
public subscript<OBase, V>(dynamicMember member: KeyPath<O, FieldContainer<OBase>.Stored<V>>) -> V? {
guard
let object = self.object,
let rawObject = object.rawObject
else {
return nil
}
return FieldContainer<OBase>.Stored<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>.Computed<V>>) -> V? {
guard
let object = self.object,
let rawObject = object.rawObject
else {
return nil
}
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.
*/