From 6d6fd3d49d69a4f0b10bb685994b1e74131ba4b2 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 7 Jun 2022 16:29:30 -0400 Subject: [PATCH] Maybe fix crash in sceneDidEnterBackground --- Tusker/MainSceneDelegate.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Tusker/MainSceneDelegate.swift b/Tusker/MainSceneDelegate.swift index f60ebdc5..0dec6de8 100644 --- a/Tusker/MainSceneDelegate.swift +++ b/Tusker/MainSceneDelegate.swift @@ -123,7 +123,10 @@ class MainSceneDelegate: UIResponder, UIWindowSceneDelegate { rootVC.sceneDidEnterBackground() } - if let context = scene.session.mastodonController?.persistentContainer.viewContext { + if let context = scene.session.mastodonController?.persistentContainer.viewContext, + // if the user quickly opens and then closes the app, this may race with loading the persistent store, so in that event we skip cleanup/save + let psc = context.persistentStoreCoordinator, + !psc.persistentStores.isEmpty { var minDate = Date() minDate.addTimeInterval(-7 * 24 * 60 * 60)