Fix crash when compose screen dismissed while adding attachments

This commit is contained in:
Shadowfacts 2024-03-25 10:06:38 -04:00
parent 3ecee61013
commit 42e29862ac
1 changed files with 5 additions and 2 deletions

View File

@ -85,8 +85,11 @@ class AttachmentsListController: ViewController {
for provider in itemProviders where provider.canLoadObject(ofClass: DraftAttachment.self) { for provider in itemProviders where provider.canLoadObject(ofClass: DraftAttachment.self) {
provider.loadObject(ofClass: DraftAttachment.self) { object, error in provider.loadObject(ofClass: DraftAttachment.self) { object, error in
guard let attachment = object as? DraftAttachment else { return } guard let attachment = object as? DraftAttachment else { return }
DispatchQueue.main.async { DispatchQueue.main.async { [weak self] in
guard self.canAddAttachment else { return } guard let self,
self.canAddAttachment else {
return
}
DraftsPersistentContainer.shared.viewContext.insert(attachment) DraftsPersistentContainer.shared.viewContext.insert(attachment)
attachment.draft = self.draft attachment.draft = self.draft
self.draft.attachments.add(attachment) self.draft.attachments.add(attachment)