From 42e29862acb3064d3321f97451502391aaa1fe00 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 25 Mar 2024 10:06:38 -0400 Subject: [PATCH] Fix crash when compose screen dismissed while adding attachments --- .../ComposeUI/Controllers/AttachmentsListController.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Packages/ComposeUI/Sources/ComposeUI/Controllers/AttachmentsListController.swift b/Packages/ComposeUI/Sources/ComposeUI/Controllers/AttachmentsListController.swift index 611a2dd304..56bae119e9 100644 --- a/Packages/ComposeUI/Sources/ComposeUI/Controllers/AttachmentsListController.swift +++ b/Packages/ComposeUI/Sources/ComposeUI/Controllers/AttachmentsListController.swift @@ -85,8 +85,11 @@ class AttachmentsListController: ViewController { for provider in itemProviders where provider.canLoadObject(ofClass: DraftAttachment.self) { provider.loadObject(ofClass: DraftAttachment.self) { object, error in guard let attachment = object as? DraftAttachment else { return } - DispatchQueue.main.async { - guard self.canAddAttachment else { return } + DispatchQueue.main.async { [weak self] in + guard let self, + self.canAddAttachment else { + return + } DraftsPersistentContainer.shared.viewContext.insert(attachment) attachment.draft = self.draft self.draft.attachments.add(attachment)