diff --git a/Memola/App/MemolaApp.swift b/Memola/App/MemolaApp.swift index 68edd1f..4804ebc 100644 --- a/Memola/App/MemolaApp.swift +++ b/Memola/App/MemolaApp.swift @@ -13,6 +13,11 @@ struct MemolaApp: App { WindowGroup { MemosView() .persistence(\.viewContext) + .onReceive(NotificationCenter.default.publisher(for: UIApplication.willTerminateNotification)) { _ in + withPersistenceSync(\.backgroundContext) { context in + try context.saveIfNeeded() + } + } } } } diff --git a/Memola/Canvas/Contexts/GraphicContext.swift b/Memola/Canvas/Contexts/GraphicContext.swift index 19b0a5f..576d44c 100644 --- a/Memola/Canvas/Contexts/GraphicContext.swift +++ b/Memola/Canvas/Contexts/GraphicContext.swift @@ -153,8 +153,10 @@ extension GraphicContext { func endStroke(at point: CGPoint) { guard currentPoint != nil, let currentStroke else { return } currentStroke.finish(at: point) - withPersistence(\.backgroundContext) { [currentStroke] context in - currentStroke.object?.bounds = currentStroke.bounds + let batchIndex = currentStroke.batchIndex + let quads = Array(currentStroke.quads[batchIndex..