mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-14 13:13:33 +01:00
Prevent crashing when DataStack is deallocated ahead of ListMonitor and child objects
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -963,8 +963,15 @@ public final class ListMonitor<D: DynamicObject>: Hashable {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
try! newFetchedResultsController.performFetchFromSpecifiedStores()
|
||||
do {
|
||||
|
||||
try newFetchedResultsController.performFetchFromSpecifiedStores()
|
||||
}
|
||||
catch {
|
||||
|
||||
// DataStack may have been deallocated
|
||||
return
|
||||
}
|
||||
self.fetchedResultsControllerDelegate.taskGroup.notify(queue: .main) {
|
||||
|
||||
self.fetchedResultsControllerDelegate.enabled = false
|
||||
|
||||
Reference in New Issue
Block a user