From a7b48ba38f3660afcd036c632d6745d1523faf63 Mon Sep 17 00:00:00 2001 From: Reed Es Date: Fri, 13 Oct 2023 18:05:36 -0600 Subject: [PATCH] mirrored fix for watch app scene-create crash #24 --- Sources/WatchApp.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sources/WatchApp.swift b/Sources/WatchApp.swift index 906247e..9d79d70 100644 --- a/Sources/WatchApp.swift +++ b/Sources/WatchApp.swift @@ -35,7 +35,10 @@ struct Watch_App: App { .environmentObject(coreDataStack) } .onChange(of: scenePhase) { _ in - // save if: (1) app moved to background, and (2) changes are pending + // save if transitioning to inactive or background + guard scenePhase == .inactive || scenePhase == .background else { return } + + // and changes are pending do { try coreDataStack.container.viewContext.save() } catch {