From 35424edbd226577977cb27895b49904611071a16 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Wed, 16 Oct 2019 13:44:10 +1100 Subject: [PATCH] Implement workaround for SR-6657 See https://bugs.swift.org/browse/SR-6657 for more information --- .../SendMediaNavigationController.swift | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/Signal/src/ViewControllers/Photos/SendMediaNavigationController.swift b/Signal/src/ViewControllers/Photos/SendMediaNavigationController.swift index e59533ee5..8e82b7eb7 100644 --- a/Signal/src/ViewControllers/Photos/SendMediaNavigationController.swift +++ b/Signal/src/ViewControllers/Photos/SendMediaNavigationController.swift @@ -192,13 +192,13 @@ class SendMediaNavigationController: OWSNavigationController { // MARK: State - private var attachmentDraftCollection: AttachmentDraftCollection = .empty + private lazy var attachmentDraftCollection = AttachmentDraftCollection.empty // Lazy to avoid https://bugs.swift.org/browse/SR-6657 private var attachments: [SignalAttachment] { return attachmentDraftCollection.attachmentDrafts.map { $0.attachment } } - private let mediaLibrarySelections: OrderedDictionary = OrderedDictionary() + private lazy var mediaLibrarySelections = OrderedDictionary() // Lazy to avoid https://bugs.swift.org/browse/SR-6657 // MARK: Child VC's @@ -463,13 +463,17 @@ private extension AttachmentDraft { } } -private struct AttachmentDraftCollection { - private(set) var attachmentDrafts: [AttachmentDraft] +private final class AttachmentDraftCollection { + lazy var attachmentDrafts = [AttachmentDraft]() // Lazy to avoid https://bugs.swift.org/browse/SR-6657 static var empty: AttachmentDraftCollection { return AttachmentDraftCollection(attachmentDrafts: []) } - + + init(attachmentDrafts: [AttachmentDraft]) { + self.attachmentDrafts = attachmentDrafts + } + // MARK: - var count: Int { @@ -498,15 +502,15 @@ private struct AttachmentDraftCollection { } } - mutating func append(_ element: AttachmentDraft) { + func append(_ element: AttachmentDraft) { attachmentDrafts.append(element) } - mutating func remove(attachment: SignalAttachment) { - attachmentDrafts = attachmentDrafts.filter { $0.attachment != attachment } + func remove(attachment: SignalAttachment) { + attachmentDrafts.removeAll { $0.attachment == attachment } } - mutating func selectedFromPicker(attachments: [MediaLibraryAttachment]) { + func selectedFromPicker(attachments: [MediaLibraryAttachment]) { let pickedAttachments: Set = Set(attachments) let oldPickerAttachments: Set = Set(self.pickerAttachments)