Implement workaround for SR-6657

See https://bugs.swift.org/browse/SR-6657 for more information
This commit is contained in:
Niels Andriesse 2019-10-16 13:44:10 +11:00
parent 93a8fdf92e
commit 35424edbd2
1 changed files with 13 additions and 9 deletions

View File

@ -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<PHAsset, MediaLibrarySelection> = OrderedDictionary()
private lazy var mediaLibrarySelections = OrderedDictionary<PHAsset, MediaLibrarySelection>() // 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<MediaLibraryAttachment> = Set(attachments)
let oldPickerAttachments: Set<MediaLibraryAttachment> = Set(self.pickerAttachments)