Implement workaround for SR-6657

See https://bugs.swift.org/browse/SR-6657 for more information
pull/58/head
Niels Andriesse 6 years ago
parent 93a8fdf92e
commit 35424edbd2

@ -192,13 +192,13 @@ class SendMediaNavigationController: OWSNavigationController {
// MARK: State // 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] { private var attachments: [SignalAttachment] {
return attachmentDraftCollection.attachmentDrafts.map { $0.attachment } 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 // MARK: Child VC's
@ -463,13 +463,17 @@ private extension AttachmentDraft {
} }
} }
private struct AttachmentDraftCollection { private final class AttachmentDraftCollection {
private(set) var attachmentDrafts: [AttachmentDraft] lazy var attachmentDrafts = [AttachmentDraft]() // Lazy to avoid https://bugs.swift.org/browse/SR-6657
static var empty: AttachmentDraftCollection { static var empty: AttachmentDraftCollection {
return AttachmentDraftCollection(attachmentDrafts: []) return AttachmentDraftCollection(attachmentDrafts: [])
} }
init(attachmentDrafts: [AttachmentDraft]) {
self.attachmentDrafts = attachmentDrafts
}
// MARK: - // MARK: -
var count: Int { var count: Int {
@ -498,15 +502,15 @@ private struct AttachmentDraftCollection {
} }
} }
mutating func append(_ element: AttachmentDraft) { func append(_ element: AttachmentDraft) {
attachmentDrafts.append(element) attachmentDrafts.append(element)
} }
mutating func remove(attachment: SignalAttachment) { func remove(attachment: SignalAttachment) {
attachmentDrafts = attachmentDrafts.filter { $0.attachment != attachment } attachmentDrafts.removeAll { $0.attachment == attachment }
} }
mutating func selectedFromPicker(attachments: [MediaLibraryAttachment]) { func selectedFromPicker(attachments: [MediaLibraryAttachment]) {
let pickedAttachments: Set<MediaLibraryAttachment> = Set(attachments) let pickedAttachments: Set<MediaLibraryAttachment> = Set(attachments)
let oldPickerAttachments: Set<MediaLibraryAttachment> = Set(self.pickerAttachments) let oldPickerAttachments: Set<MediaLibraryAttachment> = Set(self.pickerAttachments)

Loading…
Cancel
Save