Remove incorrect workaround for crash when LazilyDecoding used on nil MO

This commit is contained in:
Shadowfacts 2023-12-04 16:20:22 -05:00
parent be1ca70ebf
commit 108a02826f
1 changed files with 26 additions and 40 deletions

View File

@ -33,7 +33,6 @@ public struct LazilyDecoding<Enclosing: NSManagedObject, Value: Codable> {
public static subscript(_enclosingInstance instance: Enclosing, wrapped wrappedKeyPath: ReferenceWritableKeyPath<Enclosing, Value>, storage storageKeyPath: ReferenceWritableKeyPath<Enclosing, Self>) -> Value {
get {
instance.performOnContext {
var wrapper = instance[keyPath: storageKeyPath]
if let value = wrapper.value {
return value
@ -58,9 +57,7 @@ public struct LazilyDecoding<Enclosing: NSManagedObject, Value: Codable> {
}
}
}
}
set {
instance.performOnContext {
var wrapper = instance[keyPath: storageKeyPath]
wrapper.value = newValue
wrapper.skipClearingOnNextUpdate = true
@ -69,7 +66,6 @@ public struct LazilyDecoding<Enclosing: NSManagedObject, Value: Codable> {
instance[keyPath: wrapper.keyPath] = newData
}
}
}
mutating func removeCachedValue() {
value = nil
@ -78,16 +74,6 @@ public struct LazilyDecoding<Enclosing: NSManagedObject, Value: Codable> {
}
extension NSManagedObject {
fileprivate func performOnContext<V>(_ f: () -> V) -> V {
if let managedObjectContext {
managedObjectContext.performAndWait(f)
} else {
f()
}
}
}
extension LazilyDecoding {
init<T>(arrayFrom keyPath: ReferenceWritableKeyPath<Enclosing, Data?>) where Value == [T] {
self.init(from: keyPath, fallback: [])