From c6043d60ee1465359479c4b58a966aa6b7a9a266 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 21 Jan 2023 16:31:52 -0500 Subject: [PATCH] Fix crash when inserting present items in empty timeline --- Tusker/Screens/Timeline/TimelineViewController.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Tusker/Screens/Timeline/TimelineViewController.swift b/Tusker/Screens/Timeline/TimelineViewController.swift index dc418ecb..17e10b66 100644 --- a/Tusker/Screens/Timeline/TimelineViewController.swift +++ b/Tusker/Screens/Timeline/TimelineViewController.swift @@ -719,7 +719,11 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro // there is no existing gap applySnapshotBeforeScrolling = true } - snapshot.insertItems([.gap], beforeItem: currentItems.first!) + if let first = currentItems.first { + snapshot.insertItems([.gap], beforeItem: first) + } else { + snapshot.appendItems([.gap], toSection: .statuses) + } snapshot.insertItems(presentItems.map { .status(id: $0, collapseState: .unknown, filterState: .unknown) }, beforeItem: .gap) if applySnapshotBeforeScrolling {