Skip to content

Commit

Permalink
Implemented assertionFailure instead of fatalError
Browse files Browse the repository at this point in the history
  • Loading branch information
gokulvenkat243 committed Jan 8, 2025
1 parent dc12583 commit 4fc6630
Show file tree
Hide file tree
Showing 27 changed files with 254 additions and 79 deletions.
19 changes: 15 additions & 4 deletions Mastodon/Diffable/Report/ReportSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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
}
Expand Down
51 changes: 38 additions & 13 deletions Mastodon/Diffable/Status/StatusSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -53,15 +56,21 @@ 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,
configuration: configuration
)
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(
Expand All @@ -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
}
Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down
14 changes: 11 additions & 3 deletions Mastodon/Diffable/User/UserSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
}
Expand Down
15 changes: 12 additions & 3 deletions Mastodon/Scene/Account/AccountListViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
}
}
Expand Down
20 changes: 16 additions & 4 deletions Mastodon/Scene/Discovery/DiscoverySection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ class NotificationPolicyViewController: UIViewController {

let dataSource = UITableViewDiffableDataSource<NotificationFilterSection, NotificationFilterItem>(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]
Expand Down
Loading

0 comments on commit 4fc6630

Please sign in to comment.