Prevent crashing when DataStack is deallocated ahead of ListMonitor and child objects

This commit is contained in:
John Estropia committed 2019-06-10 18:34:15 +09:00
1 parent 30ab4386bf
commit 9f397b4337
2 files changed
+19 -4

No files matched your search

+10 -2
View File
@@ -140,8 +140,16 @@ public struct From<D: DynamicObject> {
}
internal func applyToFetchRequest<U>(_ fetchRequest: CoreStoreFetchRequest<U>, context: NSManagedObjectContext, applyAffectedStores: Bool = true) throws {
fetchRequest.entity = context.parentStack!.entityDescription(for: EntityIdentifier(self.entityClass))!
guard let parentStack = context.parentStack else {
CoreStore.log(
.warning,
message: "Attempted to perform a fetch but the \(cs_typeName(DataStack.self)) has already been deallocated."
)
throw CoreStoreError.unknown
}
fetchRequest.entity = parentStack.entityDescription(for: EntityIdentifier(self.entityClass))!
guard applyAffectedStores else {
return