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

@@ -27,6 +27,33 @@ import Foundation
import CoreData
extension DynamicObject where Self: CoreStoreObject {
public func observe<O, V>(_ keyPath: KeyPath<Self, FieldContainer<O>.Stored<V>>, options: NSKeyValueObservingOptions = [], changeHandler: @escaping (Self, CoreStoreObjectValueDiff<V>) -> Void) -> CoreStoreObjectKeyValueObservation {
let result = _CoreStoreObjectKeyValueObservation(
object: self.rawObject!,
keyPath: self[keyPath: keyPath].keyPath,
callback: { (object, kind, newValue, oldValue, _, isPrior) in
let notification = CoreStoreObjectValueDiff<V>(
kind: kind,
newNativeValue: newValue as? V.QueryableNativeType,
oldNativeValue: oldValue as? V.QueryableNativeType,
isPrior: isPrior
)
changeHandler(
Self.cs_fromRaw(object: object),
notification
)
}
)
result.start(options)
return result
}
}
// MARK: CoreStoreObjectKeyValueObservation
/**