diff --git a/Tusker/Views/Attachments/AttachmentView.swift b/Tusker/Views/Attachments/AttachmentView.swift index 2748c81257..f314ac9570 100644 --- a/Tusker/Views/Attachments/AttachmentView.swift +++ b/Tusker/Views/Attachments/AttachmentView.swift @@ -12,7 +12,7 @@ import Gifu import AVFoundation protocol AttachmentViewDelegate: class { - func attachmentViewGallery(startingAt index: Int) -> UIViewController + func attachmentViewGallery(startingAt index: Int) -> UIViewController? func attachmentViewPresent(_ vc: UIViewController, animated: Bool) } @@ -230,8 +230,8 @@ class AttachmentView: UIImageView, GIFAnimatable { } func showGallery() { - if let delegate = delegate { - let gallery = delegate.attachmentViewGallery(startingAt: index) + if let delegate = delegate, + let gallery = delegate.attachmentViewGallery(startingAt: index) { delegate.attachmentViewPresent(gallery, animated: true) } } diff --git a/Tusker/Views/Attachments/AttachmentsContainerView.swift b/Tusker/Views/Attachments/AttachmentsContainerView.swift index c7c33b22a5..90928ab847 100644 --- a/Tusker/Views/Attachments/AttachmentsContainerView.swift +++ b/Tusker/Views/Attachments/AttachmentsContainerView.swift @@ -384,8 +384,8 @@ class AttachmentsContainerView: UIView { @objc func moreViewTapped() { guard attachments.count > 4 else { return } // the more view shows up in place of the fourth attachemtn view, show tapping it should start at the fourth attachment - if let delegate = delegate { - let gallery = delegate.attachmentViewGallery(startingAt: 3) + if let delegate = delegate, + let gallery = delegate.attachmentViewGallery(startingAt: 3) { delegate.attachmentViewPresent(gallery, animated: true) } } diff --git a/Tusker/Views/Status/BaseStatusTableViewCell.swift b/Tusker/Views/Status/BaseStatusTableViewCell.swift index c528bb8472..4d83d09507 100644 --- a/Tusker/Views/Status/BaseStatusTableViewCell.swift +++ b/Tusker/Views/Status/BaseStatusTableViewCell.swift @@ -366,10 +366,11 @@ class BaseStatusTableViewCell: UITableViewCell { } extension BaseStatusTableViewCell: AttachmentViewDelegate { - func attachmentViewGallery(startingAt index: Int) -> UIViewController { - guard let status = mastodonController.persistentContainer.status(for: statusID) else { fatalError("Missing cached status \(statusID!)") } + func attachmentViewGallery(startingAt index: Int) -> UIViewController? { + guard let delegate = delegate, + let status = mastodonController.persistentContainer.status(for: statusID) else { return nil } let sourceViews = status.attachments.map(attachmentsView.getAttachmentView(for:)) - return delegate!.gallery(attachments: status.attachments, sourceViews: sourceViews, startIndex: index) + return delegate.gallery(attachments: status.attachments, sourceViews: sourceViews, startIndex: index) } func attachmentViewPresent(_ vc: UIViewController, animated: Bool) {