From cbbe9ec11f8b66a6f50abcb11a0453b344d7c3f6 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 29 Oct 2022 18:40:41 -0400 Subject: [PATCH] Fix crash in profile due to accessing data source before it exists This could happen if an account is updated in the background while a profile is on screen and the user has not visited all of the tabs. --- .../ProfileStatusesViewController.swift | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/Tusker/Screens/Profile/ProfileStatusesViewController.swift b/Tusker/Screens/Profile/ProfileStatusesViewController.swift index ed593ac5..d70e4599 100644 --- a/Tusker/Screens/Profile/ProfileStatusesViewController.swift +++ b/Tusker/Screens/Profile/ProfileStatusesViewController.swift @@ -41,16 +41,6 @@ class ProfileStatusesViewController: UIViewController, TimelineLikeCollectionVie self.controller = TimelineLikeController(delegate: self) - mastodonController.persistentContainer.accountSubject - .receive(on: DispatchQueue.main) - .filter { [unowned self] in $0 == self.accountID } - .sink { [unowned self] id in - var snapshot = dataSource.snapshot() - snapshot.reconfigureItems([.header(id)]) - dataSource.apply(snapshot, animatingDifferences: true) - } - .store(in: &cancellables) - addKeyCommand(MenuController.refreshCommand(discoverabilityTitle: "Refresh Profile")) } @@ -97,7 +87,16 @@ class ProfileStatusesViewController: UIViewController, TimelineLikeCollectionVie override func viewDidLoad() { super.viewDidLoad() - + + mastodonController.persistentContainer.accountSubject + .receive(on: DispatchQueue.main) + .filter { [unowned self] in $0 == self.accountID } + .sink { [unowned self] id in + var snapshot = dataSource.snapshot() + snapshot.reconfigureItems([.header(id)]) + dataSource.apply(snapshot, animatingDifferences: true) + } + .store(in: &cancellables) } private func createDataSource() -> UICollectionViewDiffableDataSource {