diff --git a/Mastodon/Diffable/Report/ReportSection.swift b/Mastodon/Diffable/Report/ReportSection.swift index bb7b6d79da..8e1d58433d 100644 --- a/Mastodon/Diffable/Report/ReportSection.swift +++ b/Mastodon/Diffable/Report/ReportSection.swift @@ -40,12 +40,18 @@ extension ReportSection { return UITableViewDiffableDataSource(tableView: tableView) { tableView, indexPath, item -> UITableViewCell? in switch item { case .header(let headerContext): - guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ReportHeadlineTableViewCell.self), for: indexPath) as? ReportHeadlineTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ReportHeadlineTableViewCell.self), for: indexPath) as? ReportHeadlineTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } cell.primaryLabel.text = headerContext.primaryLabelText cell.secondaryLabel.text = headerContext.secondaryLabelText return cell case .status(let status): - guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ReportStatusTableViewCell.self), for: indexPath) as? ReportStatusTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ReportStatusTableViewCell.self), for: indexPath) as? ReportStatusTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } configure( tableView: tableView, cell: cell, @@ -54,7 +60,10 @@ extension ReportSection { ) return cell case .comment(let commentContext): - guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ReportCommentTableViewCell.self), for: indexPath) as? ReportCommentTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ReportCommentTableViewCell.self), for: indexPath) as? ReportCommentTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } cell.commentTextView.text = commentContext.comment NotificationCenter.default.publisher(for: UITextView.textDidChangeNotification, object: cell.commentTextView) .receive(on: DispatchQueue.main) @@ -71,7 +80,9 @@ extension ReportSection { .store(in: &cell.disposeBag) return cell case .bottomLoader: - guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as? TimelineBottomLoaderTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as? TimelineBottomLoaderTableViewCell else { assertionFailure("unexpected cell dequeued") + return nil + } cell.activityIndicatorView.startAnimating() return cell } diff --git a/Mastodon/Diffable/Status/StatusSection.swift b/Mastodon/Diffable/Status/StatusSection.swift index 9727c7ed3b..65bfd1820b 100644 --- a/Mastodon/Diffable/Status/StatusSection.swift +++ b/Mastodon/Diffable/Status/StatusSection.swift @@ -42,7 +42,10 @@ extension StatusSection { return UITableViewDiffableDataSource(tableView: tableView) { tableView, indexPath, item -> UITableViewCell? in switch item { case .feed(let feed): - guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: StatusTableViewCell.self), for: indexPath) as? StatusTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: StatusTableViewCell.self), for: indexPath) as? StatusTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } let displayItem = StatusTableViewCell.StatusTableViewCellViewModel.DisplayItem.feed(feed) let contentConcealModel = StatusView.ContentConcealViewModel(status: feed.status, filterBox: StatusFilterService.shared.activeFilterBox, filterContext: configuration.filterContext) configure( @@ -53,7 +56,10 @@ extension StatusSection { ) return cell case .feedLoader(let feed): - guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineMiddleLoaderTableViewCell.self), for: indexPath) as? TimelineMiddleLoaderTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineMiddleLoaderTableViewCell.self), for: indexPath) as? TimelineMiddleLoaderTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } configure( cell: cell, feed: feed, @@ -61,7 +67,10 @@ extension StatusSection { ) return cell case .status(let status): - guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: StatusTableViewCell.self), for: indexPath) as? StatusTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: StatusTableViewCell.self), for: indexPath) as? StatusTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } let displayItem = StatusTableViewCell.StatusTableViewCellViewModel.DisplayItem.status(status) let contentConcealModel = StatusView.ContentConcealViewModel(status: status, filterBox: StatusFilterService.shared.activeFilterBox, filterContext: configuration.filterContext) configure( @@ -82,11 +91,15 @@ extension StatusSection { ) return cell case .topLoader: - guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as? TimelineBottomLoaderTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as? TimelineBottomLoaderTableViewCell else { assertionFailure("unexpected cell dequeued") + return nil + } cell.activityIndicatorView.startAnimating() return cell case .bottomLoader: - guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as? TimelineBottomLoaderTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as? TimelineBottomLoaderTableViewCell else { assertionFailure("unexpected cell dequeued") + return nil + } cell.activityIndicatorView.startAnimating() return cell } @@ -109,7 +122,10 @@ extension StatusSection { ) -> UITableViewCell { switch configuration.thread { case .root(let threadContext): - let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: StatusThreadRootTableViewCell.self), for: indexPath) as! StatusThreadRootTableViewCell + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: StatusThreadRootTableViewCell.self), for: indexPath) as? StatusThreadRootTableViewCell else { + assertionFailure("unexpected cell dequeued") + return UITableViewCell() + } let contentConcealModel = StatusView.ContentConcealViewModel(status: threadContext.status, filterBox: StatusFilterService.shared.activeFilterBox, filterContext: .thread) StatusSection.configure( tableView: tableView, @@ -120,7 +136,10 @@ extension StatusSection { return cell case .reply(let threadContext), .leaf(let threadContext): - let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: StatusTableViewCell.self), for: indexPath) as! StatusTableViewCell + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: StatusTableViewCell.self), for: indexPath) as? StatusTableViewCell else { + assertionFailure("unexpected cell dequeued") + return UITableViewCell() + } let displayItem = StatusTableViewCell.StatusTableViewCellViewModel.DisplayItem.status(threadContext.status) let contentConcealModel = StatusView.ContentConcealViewModel(status: threadContext.status, filterBox: StatusFilterService.shared.activeFilterBox, filterContext: configuration.configuration.filterContext) assert(configuration.configuration.filterContext == .thread) @@ -147,12 +166,15 @@ extension StatusSection { return nil case .option(let record): // Fix cell reuse animation issue - let cell: PollOptionTableViewCell = { + guard let cell: PollOptionTableViewCell = { let _cell = tableView.dequeueReusableCell(withIdentifier: String(describing: PollOptionTableViewCell.self) + "@\(indexPath.row)#\(indexPath.section)") as? PollOptionTableViewCell _cell?.prepareForReuse() return _cell ?? PollOptionTableViewCell() - }() - + }() else { + assertionFailure("unexpected cell dequeued") + return nil + } + cell.pollOptionView.viewModel.authenticationBox = authenticationBox cell.pollOptionView.configure(pollOption: record) @@ -179,12 +201,15 @@ extension StatusSection { return nil case let .history(option): // Fix cell reuse animation issue - let cell: PollOptionTableViewCell = { + guard let cell: PollOptionTableViewCell = { let _cell = tableView.dequeueReusableCell(withIdentifier: String(describing: PollOptionTableViewCell.self) + "@\(indexPath.row)#\(indexPath.section)") as? PollOptionTableViewCell _cell?.prepareForReuse() return _cell ?? PollOptionTableViewCell() - }() - + }() else { + assertionFailure("unexpected cell dequeued") + return nil + } + cell.pollOptionView.configure(historyPollOption: option) return cell diff --git a/Mastodon/Diffable/User/UserSection.swift b/Mastodon/Diffable/User/UserSection.swift index 3e12e3e344..3eeb64e0e1 100644 --- a/Mastodon/Diffable/User/UserSection.swift +++ b/Mastodon/Diffable/User/UserSection.swift @@ -34,7 +34,10 @@ extension UserSection { item -> UITableViewCell? in switch item { case .account(let account, let relationship): - guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: UserTableViewCell.self), for: indexPath) as? UserTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: UserTableViewCell.self), for: indexPath) as? UserTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } guard let me = authenticationBox.cachedAccount else { return cell } @@ -49,11 +52,16 @@ extension UserSection { return cell case .bottomLoader: - guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as? TimelineBottomLoaderTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as? TimelineBottomLoaderTableViewCell else { assertionFailure("unexpected cell dequeued") + return nil + } cell.startAnimating() return cell case .bottomHeader(let text): - guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineFooterTableViewCell.self), for: indexPath) as? TimelineFooterTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineFooterTableViewCell.self), for: indexPath) as? TimelineFooterTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } cell.messageLabel.text = text return cell } diff --git a/Mastodon/Protocol/Provider/DataSourceProvider+UITableViewDelegate.swift b/Mastodon/Protocol/Provider/DataSourceProvider+UITableViewDelegate.swift index dc0a1eb6d0..5c0d850ee6 100644 --- a/Mastodon/Protocol/Provider/DataSourceProvider+UITableViewDelegate.swift +++ b/Mastodon/Protocol/Provider/DataSourceProvider+UITableViewDelegate.swift @@ -71,7 +71,10 @@ extension UITableViewDelegate where Self: DataSourceProvider & MediaPreviewableV indexPath: IndexPath, point: CGPoint ) -> UIContextMenuConfiguration? { - guard let cell = tableView.cellForRow(at: indexPath) as? StatusViewContainerTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.cellForRow(at: indexPath) as? StatusViewContainerTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } let mediaViews = cell.statusView.mediaGridContainerView.mediaViews @@ -218,6 +221,7 @@ extension UITableViewDelegate where Self: DataSourceProvider & MediaPreviewableV parameters.visiblePath = UIBezierPath(roundedRect: mediaView.bounds, cornerRadius: MediaView.cornerRadius) return UITargetedPreview(view: mediaView, parameters: parameters) } else { + assertionFailure("unexpected cell dequeued") return nil } } diff --git a/Mastodon/Scene/Account/AccountListViewModel.swift b/Mastodon/Scene/Account/AccountListViewModel.swift index aebad02134..2a808403c5 100644 --- a/Mastodon/Scene/Account/AccountListViewModel.swift +++ b/Mastodon/Scene/Account/AccountListViewModel.swift @@ -73,7 +73,10 @@ extension AccountListViewModel { diffableDataSource = UITableViewDiffableDataSource(tableView: tableView) { tableView, indexPath, item in switch item { case .authentication(let record): - guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: AccountListTableViewCell.self), for: indexPath) as? AccountListTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: AccountListTableViewCell.self), for: indexPath) as? AccountListTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } if let activeAuthentication = AuthenticationServiceProvider.shared.currentActiveUser.value { AccountListViewModel.configure( @@ -84,10 +87,16 @@ extension AccountListViewModel { } return cell case .addAccount: - guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: AddAccountTableViewCell.self), for: indexPath) as? AddAccountTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: AddAccountTableViewCell.self), for: indexPath) as? AddAccountTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } return cell case .logoutOfAllAccounts: - guard let cell = tableView.dequeueReusableCell(withIdentifier: LogoutOfAllAccountsCell.reuseIdentifier, for: indexPath) as? LogoutOfAllAccountsCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: LogoutOfAllAccountsCell.reuseIdentifier, for: indexPath) as? LogoutOfAllAccountsCell else { + assertionFailure("unexpected cell dequeued") + return nil + } return cell } } diff --git a/Mastodon/Scene/Discovery/DiscoverySection.swift b/Mastodon/Scene/Discovery/DiscoverySection.swift index a5e6d0c131..0845beb35d 100644 --- a/Mastodon/Scene/Discovery/DiscoverySection.swift +++ b/Mastodon/Scene/Discovery/DiscoverySection.swift @@ -51,16 +51,25 @@ extension DiscoverySection { item in switch item { case .hashtag(let tag): - guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TrendTableViewCell.self), for: indexPath) as? TrendTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TrendTableViewCell.self), for: indexPath) as? TrendTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } cell.trendView.configure(tag: tag) return cell case .link(let link): - guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: NewsTableViewCell.self), for: indexPath) as? NewsTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: NewsTableViewCell.self), for: indexPath) as? NewsTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } cell.newsView.configure(link: link) return cell case .account(let account, relationship: let relationship): guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ProfileCardTableViewCell.self), for: indexPath) as? - ProfileCardTableViewCell else { fatalError("WTF?! Wrong cell.") } + ProfileCardTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } cell.configure( tableView: tableView, @@ -81,7 +90,10 @@ extension DiscoverySection { return cell case .bottomLoader: - guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as? TimelineBottomLoaderTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as? TimelineBottomLoaderTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } cell.activityIndicatorView.startAnimating() return cell } diff --git a/Mastodon/Scene/Notification/Notification Filtering/Policy/NotificationPolicyViewController.swift b/Mastodon/Scene/Notification/Notification Filtering/Policy/NotificationPolicyViewController.swift index d7d0dfe091..78051dcd36 100644 --- a/Mastodon/Scene/Notification/Notification Filtering/Policy/NotificationPolicyViewController.swift +++ b/Mastodon/Scene/Notification/Notification Filtering/Policy/NotificationPolicyViewController.swift @@ -90,7 +90,8 @@ class NotificationPolicyViewController: UIViewController { let dataSource = UITableViewDiffableDataSource(tableView: tableView) { [weak self] tableView, indexPath, itemIdentifier in guard let self, let cell = tableView.dequeueReusableCell(withIdentifier: NotificationPolicyFilterTableViewCell.reuseIdentifier, for: indexPath) as? NotificationPolicyFilterTableViewCell else { - fatalError("No NotificationPolicyFilterTableViewCell") + assertionFailure("unexpected cell dequeued") + return nil } let item = items[indexPath.row] diff --git a/Mastodon/Scene/Notification/Notification Filtering/Requests/NotificationRequestsTableViewController.swift b/Mastodon/Scene/Notification/Notification Filtering/Requests/NotificationRequestsTableViewController.swift index d29dc8dd3a..1b2906c0e8 100644 --- a/Mastodon/Scene/Notification/Notification Filtering/Requests/NotificationRequestsTableViewController.swift +++ b/Mastodon/Scene/Notification/Notification Filtering/Requests/NotificationRequestsTableViewController.swift @@ -42,7 +42,8 @@ class NotificationRequestsTableViewController: UIViewController { let dataSource = UITableViewDiffableDataSource(tableView: tableView) { tableView, indexPath, itemIdentifier in guard let cell = tableView.dequeueReusableCell(withIdentifier: NotificationRequestTableViewCell.reuseIdentifier, for: indexPath) as? NotificationRequestTableViewCell else { - fatalError("No NotificationRequestTableViewCell") + assertionFailure("unexpected cell dequeued") + return nil } let request = viewModel.requests[indexPath.row] diff --git a/Mastodon/Scene/Notification/NotificationSection.swift b/Mastodon/Scene/Notification/NotificationSection.swift index 89d96e3cd2..96f6cf1d2f 100644 --- a/Mastodon/Scene/Notification/NotificationSection.swift +++ b/Mastodon/Scene/Notification/NotificationSection.swift @@ -43,13 +43,17 @@ extension NotificationSection { switch item { case .feed(let feed): if let notification = feed.notification, let accountWarning = notification.accountWarning { - guard let cell = tableView.dequeueReusableCell(withIdentifier: AccountWarningNotificationCell.reuseIdentifier, for: indexPath) as? - AccountWarningNotificationCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: AccountWarningNotificationCell.reuseIdentifier, for: indexPath) as? AccountWarningNotificationCell else { + assertionFailure("unexpected cell dequeued") + return nil + } cell.configure(with: accountWarning) return cell } else { - guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: NotificationTableViewCell.self), for: indexPath) as? - NotificationTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: NotificationTableViewCell.self), for: indexPath) as? NotificationTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } configure( tableView: tableView, cell: cell, @@ -60,18 +64,24 @@ extension NotificationSection { } case .feedLoader: - guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as? - TimelineBottomLoaderTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as? TimelineBottomLoaderTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } cell.activityIndicatorView.startAnimating() return cell case .bottomLoader: - guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as? - TimelineBottomLoaderTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as? TimelineBottomLoaderTableViewCell else { assertionFailure("unexpected cell dequeued") + return nil + } cell.activityIndicatorView.startAnimating() return cell case .filteredNotifications(let policy): - guard let cell = tableView.dequeueReusableCell(withIdentifier: NotificationFilteringBannerTableViewCell.reuseIdentifier, for: indexPath) as? NotificationFilteringBannerTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: NotificationFilteringBannerTableViewCell.reuseIdentifier, for: indexPath) as? NotificationFilteringBannerTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } cell.configure(with: policy) return cell diff --git a/Mastodon/Scene/Onboarding/Login/MastodonLoginViewController.swift b/Mastodon/Scene/Onboarding/Login/MastodonLoginViewController.swift index 73f71c3415..13c11491d0 100644 --- a/Mastodon/Scene/Onboarding/Login/MastodonLoginViewController.swift +++ b/Mastodon/Scene/Onboarding/Login/MastodonLoginViewController.swift @@ -70,7 +70,8 @@ class MastodonLoginViewController: UIViewController { let dataSource = UITableViewDiffableDataSource(tableView: contentView.tableView) { [weak self] tableView, indexPath, itemIdentifier in guard let cell = tableView.dequeueReusableCell(withIdentifier: MastodonLoginServerTableViewCell.reuseIdentifier, for: indexPath) as? MastodonLoginServerTableViewCell, let self else { - fatalError("Wrong cell") + assertionFailure("unexpected cell dequeued") + return nil } let server = self.viewModel.filteredServers[indexPath.row] diff --git a/Mastodon/Scene/Onboarding/PickServer/CategoryPickerSection.swift b/Mastodon/Scene/Onboarding/PickServer/CategoryPickerSection.swift index 4f551a403e..d34d48d760 100644 --- a/Mastodon/Scene/Onboarding/PickServer/CategoryPickerSection.swift +++ b/Mastodon/Scene/Onboarding/PickServer/CategoryPickerSection.swift @@ -22,7 +22,10 @@ extension CategoryPickerSection { ) -> UICollectionViewDiffableDataSource { UICollectionViewDiffableDataSource(collectionView: collectionView) { [weak dependency] collectionView, indexPath, item -> UICollectionViewCell? in guard let _ = dependency else { return nil } - let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PickServerCategoryCollectionViewCell.reuseIdentifier, for: indexPath) as! PickServerCategoryCollectionViewCell + guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PickServerCategoryCollectionViewCell.reuseIdentifier, for: indexPath) as? PickServerCategoryCollectionViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } cell.titleLabel.text = item.title diff --git a/Mastodon/Scene/Onboarding/PickServer/PickServerSection.swift b/Mastodon/Scene/Onboarding/PickServer/PickServerSection.swift index 99b69eb3f1..657e3cd0f3 100644 --- a/Mastodon/Scene/Onboarding/PickServer/PickServerSection.swift +++ b/Mastodon/Scene/Onboarding/PickServer/PickServerSection.swift @@ -29,11 +29,17 @@ extension PickServerSection { guard let _ = dependency else { return nil } switch item { case .server(let server, let attribute): - guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: PickServerCell.self), for: indexPath) as? PickServerCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: PickServerCell.self), for: indexPath) as? PickServerCell else { + assertionFailure("unexpected cell dequeued") + return nil + } PickServerSection.configure(cell: cell, server: server, attribute: attribute) return cell case .loader(let attribute): - guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: PickServerLoaderTableViewCell.self), for: indexPath) as? PickServerLoaderTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: PickServerLoaderTableViewCell.self), for: indexPath) as? PickServerLoaderTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } PickServerSection.configure(cell: cell, attribute: attribute) return cell } diff --git a/Mastodon/Scene/Onboarding/Privacy/PrivacyTableViewController.swift b/Mastodon/Scene/Onboarding/Privacy/PrivacyTableViewController.swift index 37baa62fa3..5c980939b7 100644 --- a/Mastodon/Scene/Onboarding/Privacy/PrivacyTableViewController.swift +++ b/Mastodon/Scene/Onboarding/Privacy/PrivacyTableViewController.swift @@ -92,7 +92,10 @@ extension PrivacyTableViewController: UITableViewDataSource { } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - guard let cell = tableView.dequeueReusableCell(withIdentifier: PrivacyTableViewCell.reuseIdentifier, for: indexPath) as? PrivacyTableViewCell else { fatalError("Wrong cell?") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: PrivacyTableViewCell.reuseIdentifier, for: indexPath) as? PrivacyTableViewCell else { + assertionFailure("unexpected cell dequeued") + return UITableViewCell() + } let row = viewModel.rows[indexPath.row] diff --git a/Mastodon/Scene/Onboarding/ServerRules/ServerRuleSection.swift b/Mastodon/Scene/Onboarding/ServerRules/ServerRuleSection.swift index 6ca44baccb..64051029bc 100644 --- a/Mastodon/Scene/Onboarding/ServerRules/ServerRuleSection.swift +++ b/Mastodon/Scene/Onboarding/ServerRules/ServerRuleSection.swift @@ -20,7 +20,10 @@ extension ServerRuleSection { return UITableViewDiffableDataSource(tableView: tableView) { tableView, indexPath, item in switch item { case .rule(let index, let rule): - guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ServerRulesTableViewCell.self), for: indexPath) as? ServerRulesTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ServerRulesTableViewCell.self), for: indexPath) as? ServerRulesTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } cell.indexImageView.image = UIImage(systemName: "\(index + 1).circle") ?? UIImage(systemName: "questionmark.circle") cell.indexImageView.tintColor = Asset.Colors.Brand.lightBlurple.color cell.ruleLabel.text = rule.text diff --git a/Mastodon/Scene/Profile/FollowedTags/FollowedTagsViewModel+DiffableDataSource.swift b/Mastodon/Scene/Profile/FollowedTags/FollowedTagsViewModel+DiffableDataSource.swift index 781bc353a1..0e3e2f906a 100644 --- a/Mastodon/Scene/Profile/FollowedTags/FollowedTagsViewModel+DiffableDataSource.swift +++ b/Mastodon/Scene/Profile/FollowedTags/FollowedTagsViewModel+DiffableDataSource.swift @@ -25,8 +25,8 @@ extension FollowedTagsViewModel { switch item { case let .hashtag(tag): guard let cell = tableView.dequeueReusableCell(withIdentifier: FollowedTagsTableViewCell.reuseIdentifier, for: indexPath) as? FollowedTagsTableViewCell else { - assertionFailure() - return UITableViewCell() + assertionFailure("unexpected cell dequeued") + return nil } cell.setup(self) diff --git a/Mastodon/Scene/Search/SearchDetail/Search Results Overview/SearchResultsOverviewTableViewController.swift b/Mastodon/Scene/Search/SearchDetail/Search Results Overview/SearchResultsOverviewTableViewController.swift index fbd7190452..f6432f5775 100644 --- a/Mastodon/Scene/Search/SearchDetail/Search Results Overview/SearchResultsOverviewTableViewController.swift +++ b/Mastodon/Scene/Search/SearchDetail/Search Results Overview/SearchResultsOverviewTableViewController.swift @@ -46,7 +46,10 @@ class SearchResultsOverviewTableViewController: UIViewController, AuthContextPro switch itemIdentifier { case .default(let item): - guard let cell = tableView.dequeueReusableCell(withIdentifier: SearchResultDefaultSectionTableViewCell.reuseIdentifier, for: indexPath) as? SearchResultDefaultSectionTableViewCell else { fatalError() } + guard let cell = tableView.dequeueReusableCell(withIdentifier: SearchResultDefaultSectionTableViewCell.reuseIdentifier, for: indexPath) as? SearchResultDefaultSectionTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } cell.configure(item: item) @@ -55,13 +58,19 @@ class SearchResultsOverviewTableViewController: UIViewController, AuthContextPro case .suggestion(let suggestion): switch suggestion { case .hashtag(let hashtag): - guard let cell = tableView.dequeueReusableCell(withIdentifier: SearchResultDefaultSectionTableViewCell.reuseIdentifier, for: indexPath) as? SearchResultDefaultSectionTableViewCell else { fatalError() } + guard let cell = tableView.dequeueReusableCell(withIdentifier: SearchResultDefaultSectionTableViewCell.reuseIdentifier, for: indexPath) as? SearchResultDefaultSectionTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } cell.configure(item: .hashtag(tag: hashtag)) return cell case .profile(let profile): - guard let cell = tableView.dequeueReusableCell(withIdentifier: SearchResultsProfileTableViewCell.reuseIdentifier, for: indexPath) as? SearchResultsProfileTableViewCell else { fatalError() } + guard let cell = tableView.dequeueReusableCell(withIdentifier: SearchResultsProfileTableViewCell.reuseIdentifier, for: indexPath) as? SearchResultsProfileTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } cell.condensedUserView.configure(with: profile) diff --git a/Mastodon/Scene/Search/SearchDetail/SearchResult/SearchResultSection.swift b/Mastodon/Scene/Search/SearchDetail/SearchResult/SearchResultSection.swift index 4878157d41..ab45af2fd1 100644 --- a/Mastodon/Scene/Search/SearchDetail/SearchResult/SearchResultSection.swift +++ b/Mastodon/Scene/Search/SearchDetail/SearchResult/SearchResultSection.swift @@ -41,7 +41,10 @@ extension SearchResultSection { return UITableViewDiffableDataSource(tableView: tableView) { tableView, indexPath, item -> UITableViewCell? in switch item { case .account(let account, let relationship): - guard let cell = tableView.dequeueReusableCell(withIdentifier: UserTableViewCell.reuseIdentifier, for: indexPath) as? UserTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: UserTableViewCell.reuseIdentifier, for: indexPath) as? UserTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } guard let me = authenticationBox.cachedAccount else { return cell } @@ -55,8 +58,10 @@ extension SearchResultSection { ) return cell case .status(let status): - guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: StatusTableViewCell.self), for: indexPath) as? - StatusTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: StatusTableViewCell.self), for: indexPath) as? StatusTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } let displayItem = StatusTableViewCell.StatusTableViewCellViewModel.DisplayItem.status(status) let contentConcealModel = StatusView.ContentConcealViewModel(status: status, filterBox: StatusFilterService.shared.activeFilterBox, filterContext: nil) // no filters in search results configure( @@ -67,11 +72,17 @@ extension SearchResultSection { ) return cell case .hashtag(let tag): - guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: HashtagTableViewCell.self)) as? HashtagTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: HashtagTableViewCell.self)) as? HashtagTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } cell.primaryLabel.configure(content: PlaintextMetaContent(string: "#" + tag.name)) return cell case .bottomLoader(let attribute): - let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self)) as! TimelineBottomLoaderTableViewCell + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self)) as? TimelineBottomLoaderTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } if attribute.isNoResult { cell.stopAnimating() cell.loadMoreLabel.text = L10n.Scene.Search.Searching.EmptyState.noResults diff --git a/Mastodon/Scene/Settings/About Mastodon/AboutViewController.swift b/Mastodon/Scene/Settings/About Mastodon/AboutViewController.swift index 85fd737884..8ccf626214 100644 --- a/Mastodon/Scene/Settings/About Mastodon/AboutViewController.swift +++ b/Mastodon/Scene/Settings/About Mastodon/AboutViewController.swift @@ -41,8 +41,11 @@ class AboutViewController: UIViewController { let tableViewDataSource = UITableViewDiffableDataSource(tableView: tableView) { [weak self] tableView, indexPath, itemIdentifier in guard let self, - let cell = tableView.dequeueReusableCell(withIdentifier: AboutMastodonTableViewCell.reuseIdentifier, for: indexPath) as? AboutMastodonTableViewCell else { fatalError("WTF?? Wrong Cell dude!") } - + let cell = tableView.dequeueReusableCell(withIdentifier: AboutMastodonTableViewCell.reuseIdentifier, for: indexPath) as? AboutMastodonTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } + let entry = self.sections[indexPath.section].entries[indexPath.row] cell.configure(with: entry) diff --git a/Mastodon/Scene/Settings/General Settings/GeneralSettingsViewController.swift b/Mastodon/Scene/Settings/General Settings/GeneralSettingsViewController.swift index 9586af09c4..67fb63cff6 100644 --- a/Mastodon/Scene/Settings/General Settings/GeneralSettingsViewController.swift +++ b/Mastodon/Scene/Settings/General Settings/GeneralSettingsViewController.swift @@ -93,30 +93,45 @@ class GeneralSettingsViewController: UIViewController { let cell: UITableViewCell switch itemIdentifier { case .appearance(let setting): - guard let selectionCell = tableView.dequeueReusableCell(withIdentifier: GeneralSettingSelectionCell.reuseIdentifier, for: indexPath) as? GeneralSettingSelectionCell else { fatalError("WTF? Wrong Cell!") } + guard let selectionCell = tableView.dequeueReusableCell(withIdentifier: GeneralSettingSelectionCell.reuseIdentifier, for: indexPath) as? GeneralSettingSelectionCell else { + assertionFailure("unexpected cell dequeued") + return nil + } selectionCell.configure(with: .appearance(setting), viewModel: self.viewModel) cell = selectionCell case .askBefore(let setting): - guard let toggleCell = tableView.dequeueReusableCell(withIdentifier: GeneralSettingToggleTableViewCell.reuseIdentifier, for: indexPath) as? GeneralSettingToggleTableViewCell else { fatalError("WTF? Wrong Cell!") } + guard let toggleCell = tableView.dequeueReusableCell(withIdentifier: GeneralSettingToggleTableViewCell.reuseIdentifier, for: indexPath) as? GeneralSettingToggleTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } toggleCell.configure(with: .askBefore(setting), viewModel: self.viewModel) toggleCell.delegate = self cell = toggleCell case .design(let setting): - guard let toggleCell = tableView.dequeueReusableCell(withIdentifier: GeneralSettingToggleTableViewCell.reuseIdentifier, for: indexPath) as? GeneralSettingToggleTableViewCell else { fatalError("WTF? Wrong Cell!") } + guard let toggleCell = tableView.dequeueReusableCell(withIdentifier: GeneralSettingToggleTableViewCell.reuseIdentifier, for: indexPath) as? GeneralSettingToggleTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } toggleCell.configure(with: .design(setting), viewModel: self.viewModel) toggleCell.delegate = self cell = toggleCell case let .language(setting): - guard let selectionCell = tableView.dequeueReusableCell(withIdentifier: GeneralSettingSelectionCell.reuseIdentifier, for: indexPath) as? GeneralSettingSelectionCell else { fatalError("WTF? Wrong Cell!") } + guard let selectionCell = tableView.dequeueReusableCell(withIdentifier: GeneralSettingSelectionCell.reuseIdentifier, for: indexPath) as? GeneralSettingSelectionCell else { + assertionFailure("unexpected cell dequeued") + return nil + } selectionCell.configure(with: .language(setting), viewModel: self.viewModel) cell = selectionCell case .openLinksIn(let setting): - guard let selectionCell = tableView.dequeueReusableCell(withIdentifier: GeneralSettingSelectionCell.reuseIdentifier, for: indexPath) as? GeneralSettingSelectionCell else { fatalError("WTF? Wrong Cell!") } + guard let selectionCell = tableView.dequeueReusableCell(withIdentifier: GeneralSettingSelectionCell.reuseIdentifier, for: indexPath) as? GeneralSettingSelectionCell else { + assertionFailure("unexpected cell dequeued") + return nil + } selectionCell.configure(with: .openLinksIn(setting), viewModel: self.viewModel) diff --git a/Mastodon/Scene/Settings/Notification Settings/NotificationSettingsViewController.swift b/Mastodon/Scene/Settings/Notification Settings/NotificationSettingsViewController.swift index f1d249e45c..4c9ba65160 100644 --- a/Mastodon/Scene/Settings/Notification Settings/NotificationSettingsViewController.swift +++ b/Mastodon/Scene/Settings/Notification Settings/NotificationSettingsViewController.swift @@ -56,21 +56,30 @@ class NotificationSettingsViewController: UIViewController { switch itemIdentifier { case .notificationDisabled: - guard let notificationsDisabledCell = tableView.dequeueReusableCell(withIdentifier: NotificationSettingsDisabledTableViewCell.reuseIdentifier, for: indexPath) as? NotificationSettingsDisabledTableViewCell else { fatalError("WTF Wrong cell!?") } + guard let notificationsDisabledCell = tableView.dequeueReusableCell(withIdentifier: NotificationSettingsDisabledTableViewCell.reuseIdentifier, for: indexPath) as? NotificationSettingsDisabledTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } cell = notificationsDisabledCell case .policy: guard let self, - let notificationCell = tableView.dequeueReusableCell(withIdentifier: NotificationSettingTableViewCell.reuseIdentifier, for: indexPath) as? NotificationSettingTableViewCell else { fatalError("WTF Wrong cell!?") } + let notificationCell = tableView.dequeueReusableCell(withIdentifier: NotificationSettingTableViewCell.reuseIdentifier, for: indexPath) as? NotificationSettingTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } notificationCell.configure(with: .policy, viewModel: self.viewModel, notificationsEnabled: notificationsEnabled) cell = notificationCell case .alert(let alert): guard let self, - let toggleCell = tableView.dequeueReusableCell(withIdentifier: NotificationSettingTableViewToggleCell.reuseIdentifier, for: indexPath) as? NotificationSettingTableViewToggleCell else { fatalError("WTF Wrong cell!?") } - + let toggleCell = tableView.dequeueReusableCell(withIdentifier: NotificationSettingTableViewToggleCell.reuseIdentifier, for: indexPath) as? NotificationSettingTableViewToggleCell else { + assertionFailure("unexpected cell dequeued") + return nil + } + toggleCell.configure(with: alert, viewModel: self.viewModel, notificationsEnabled: notificationsEnabled) toggleCell.delegate = self cell = toggleCell diff --git a/Mastodon/Scene/Settings/Notification Settings/Policy Selection/PolicySelectionViewController.swift b/Mastodon/Scene/Settings/Notification Settings/Policy Selection/PolicySelectionViewController.swift index b0fa34caec..e1e5a139b1 100644 --- a/Mastodon/Scene/Settings/Notification Settings/Policy Selection/PolicySelectionViewController.swift +++ b/Mastodon/Scene/Settings/Notification Settings/Policy Selection/PolicySelectionViewController.swift @@ -29,7 +29,8 @@ class PolicySelectionViewController: UIViewController { let dataSource = UITableViewDiffableDataSource(tableView: tableView) { [weak self] tableView, indexPath, itemIdentifier in guard let self, let cell = tableView.dequeueReusableCell(withIdentifier: NotificationPolicyTableViewCell.reuseIdentifier, for: indexPath) as? NotificationPolicyTableViewCell else { - fatalError("WTF Wrong cell?!") + assertionFailure("unexpected cell dequeued") + return nil } let policy = self.sections[indexPath.section].entries[indexPath.row] diff --git a/Mastodon/Scene/Settings/Server Details/AboutInstanceViewController.swift b/Mastodon/Scene/Settings/Server Details/AboutInstanceViewController.swift index 444f5c3faa..ebc0175fd1 100644 --- a/Mastodon/Scene/Settings/Server Details/AboutInstanceViewController.swift +++ b/Mastodon/Scene/Settings/Server Details/AboutInstanceViewController.swift @@ -40,14 +40,20 @@ class AboutInstanceViewController: UIViewController, AuthContextProvider { switch itemIdentifier { case .adminAccount(let account): - guard let cell = tableView.dequeueReusableCell(withIdentifier: AdminTableViewCell.reuseIdentifier, for: indexPath) as? AdminTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: AdminTableViewCell.reuseIdentifier, for: indexPath) as? AdminTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } cell.condensedUserView.configure(with: account, showFollowers: false) return cell case .contactAdmin: - guard let cell = tableView.dequeueReusableCell(withIdentifier: ContactAdminTableViewCell.reuseIdentifier, for: indexPath) as? ContactAdminTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: ContactAdminTableViewCell.reuseIdentifier, for: indexPath) as? ContactAdminTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } cell.configure() diff --git a/Mastodon/Scene/Settings/Settings Overview/SettingsViewController.swift b/Mastodon/Scene/Settings/Settings Overview/SettingsViewController.swift index 418343a36d..dac4a4e4ea 100644 --- a/Mastodon/Scene/Settings/Settings Overview/SettingsViewController.swift +++ b/Mastodon/Scene/Settings/Settings Overview/SettingsViewController.swift @@ -42,8 +42,10 @@ class SettingsViewController: UIViewController { let tableViewDataSource = UITableViewDiffableDataSource(tableView: tableView) { [weak self] tableView, indexPath, itemIdentifier in guard let self, - let cell = tableView.dequeueReusableCell(withIdentifier: SettingsTableViewCell.reuseIdentifier, for: indexPath) as? SettingsTableViewCell - else { fatalError("Wrong cell WTF??") } + let cell = tableView.dequeueReusableCell(withIdentifier: SettingsTableViewCell.reuseIdentifier, for: indexPath) as? SettingsTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } let entry = self.sections[indexPath.section].entries[indexPath.row] cell.update(with: entry) diff --git a/Mastodon/Scene/SuggestionAccount/RecommendAccountSection.swift b/Mastodon/Scene/SuggestionAccount/RecommendAccountSection.swift index aaa288b5d2..c1b9a12256 100644 --- a/Mastodon/Scene/SuggestionAccount/RecommendAccountSection.swift +++ b/Mastodon/Scene/SuggestionAccount/RecommendAccountSection.swift @@ -32,7 +32,10 @@ extension RecommendAccountSection { ) -> UITableViewDiffableDataSource { UITableViewDiffableDataSource(tableView: tableView) { tableView, indexPath, item -> UITableViewCell? in guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: SuggestionAccountTableViewCell.self)) as? - SuggestionAccountTableViewCell else { fatalError("WTF?! Wrong cell.") } + SuggestionAccountTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } switch item { case .account(let account, let relationship): cell.delegate = configuration.suggestionAccountTableViewCellDelegate diff --git a/Mastodon/Scene/Thread/Edit History/StatusEditHistoryViewController.swift b/Mastodon/Scene/Thread/Edit History/StatusEditHistoryViewController.swift index 42bb16b615..dd6b2cae1a 100644 --- a/Mastodon/Scene/Thread/Edit History/StatusEditHistoryViewController.swift +++ b/Mastodon/Scene/Thread/Edit History/StatusEditHistoryViewController.swift @@ -31,7 +31,8 @@ class StatusEditHistoryViewController: UIViewController { let tableViewDataSource = UITableViewDiffableDataSource(tableView: tableView) {tableView, indexPath, itemIdentifier in guard let cell = tableView.dequeueReusableCell(withIdentifier: StatusEditHistoryTableViewCell.identifier, for: indexPath) as? StatusEditHistoryTableViewCell else { - fatalError("Wrong cell") + assertionFailure("unexpected cell dequeued") + return nil } let statusEdit = viewModel.edits[indexPath.row] diff --git a/MastodonSDK/Sources/MastodonUI/DataSource/AutoCompleteSection+Diffable.swift b/MastodonSDK/Sources/MastodonUI/DataSource/AutoCompleteSection+Diffable.swift index 87493f3050..0eaf8b67e5 100644 --- a/MastodonSDK/Sources/MastodonUI/DataSource/AutoCompleteSection+Diffable.swift +++ b/MastodonSDK/Sources/MastodonUI/DataSource/AutoCompleteSection+Diffable.swift @@ -19,23 +19,37 @@ extension AutoCompleteSection { UITableViewDiffableDataSource(tableView: tableView) { tableView, indexPath, item in switch item { case .hashtag(let hashtag): - guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: AutoCompleteTableViewCell.self), for: indexPath) as? AutoCompleteTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: AutoCompleteTableViewCell.self), for: indexPath) as? AutoCompleteTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } configureHashtag(cell: cell, hashtag: hashtag) return cell case .hashtagV1(let hashtagName): - guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: AutoCompleteTableViewCell.self), for: indexPath) as? AutoCompleteTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: AutoCompleteTableViewCell.self), for: indexPath) as? AutoCompleteTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } configureHashtag(cell: cell, hashtagName: hashtagName) return cell case .account(let account): - guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: AutoCompleteTableViewCell.self), for: indexPath) as? AutoCompleteTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: AutoCompleteTableViewCell.self), for: indexPath) as? AutoCompleteTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } configureAccount(cell: cell, account: account) return cell case .emoji(let emoji): - guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: AutoCompleteTableViewCell.self), for: indexPath) as? AutoCompleteTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: AutoCompleteTableViewCell.self), for: indexPath) as? AutoCompleteTableViewCell else { + assertionFailure("unexpected cell dequeued") + return nil + } configureEmoji(cell: cell, emoji: emoji, isFirst: indexPath.row == 0) return cell case .bottomLoader: - guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as? TimelineBottomLoaderTableViewCell else { fatalError("WTF?! Wrong cell.") } + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as? TimelineBottomLoaderTableViewCell else { assertionFailure("unexpected cell dequeued") + return nil + } cell.startAnimating() return cell } diff --git a/MastodonSDK/Sources/MastodonUI/DataSource/CustomEmojiPickerSection+Diffable.swift b/MastodonSDK/Sources/MastodonUI/DataSource/CustomEmojiPickerSection+Diffable.swift index 5b4717047d..a07da35b32 100644 --- a/MastodonSDK/Sources/MastodonUI/DataSource/CustomEmojiPickerSection+Diffable.swift +++ b/MastodonSDK/Sources/MastodonUI/DataSource/CustomEmojiPickerSection+Diffable.swift @@ -16,7 +16,11 @@ extension CustomEmojiPickerSection { let dataSource = UICollectionViewDiffableDataSource(collectionView: collectionView) { collectionView, indexPath, item -> UICollectionViewCell? in switch item { case .emoji(let attribute): - let cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: CustomEmojiPickerItemCollectionViewCell.self), for: indexPath) as! CustomEmojiPickerItemCollectionViewCell + guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: CustomEmojiPickerItemCollectionViewCell.self), for: indexPath) as? CustomEmojiPickerItemCollectionViewCell + else { + assertionFailure("unexpected cell dequeued") + return nil + } let placeholder = UIImage.placeholder(size: CustomEmojiPickerItemCollectionViewCell.itemSize, color: .systemFill) .af.imageRounded(withCornerRadius: 4)