From 4644475bc732de3e292cf1614286dbdbb1abc2bc Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 2 Nov 2022 22:53:07 -0400 Subject: [PATCH] Fix crashes when ProfileStatusesVC doesn't finish loading until ProfileVC is deinit'd --- Tusker/Screens/Profile/ProfileStatusesViewController.swift | 7 ++++--- Tusker/Views/Profile Header/ProfileHeaderView.swift | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Tusker/Screens/Profile/ProfileStatusesViewController.swift b/Tusker/Screens/Profile/ProfileStatusesViewController.swift index 85e1f34d..de377ebd 100644 --- a/Tusker/Screens/Profile/ProfileStatusesViewController.swift +++ b/Tusker/Screens/Profile/ProfileStatusesViewController.swift @@ -12,8 +12,8 @@ import Combine class ProfileStatusesViewController: UIViewController, TimelineLikeCollectionViewController { - unowned var owner: ProfileViewController - var mastodonController: MastodonController { owner.mastodonController } + weak var owner: ProfileViewController? + let mastodonController: MastodonController private(set) var accountID: String! let kind: Kind var initialHeaderMode: HeaderMode? @@ -37,6 +37,7 @@ class ProfileStatusesViewController: UIViewController, TimelineLikeCollectionVie self.accountID = accountID self.kind = kind self.owner = owner + self.mastodonController = owner.mastodonController super.init(nibName: nil, bundle: nil) @@ -130,7 +131,7 @@ class ProfileStatusesViewController: UIViewController, TimelineLikeCollectionVie let view = ProfileHeaderView.create() view.delegate = self.profileHeaderDelegate view.updateUI(for: id) - view.pagesSegmentedControl.selectedSegmentIndex = self.owner.currentIndex ?? 0 + view.pagesSegmentedControl.selectedSegmentIndex = self.owner?.currentIndex ?? 0 cell.addHeader(view) case .placeholder(height: let height): _ = cell.addConstraint(height: height) diff --git a/Tusker/Views/Profile Header/ProfileHeaderView.swift b/Tusker/Views/Profile Header/ProfileHeaderView.swift index bb223171..b6659d24 100644 --- a/Tusker/Views/Profile Header/ProfileHeaderView.swift +++ b/Tusker/Views/Profile Header/ProfileHeaderView.swift @@ -119,12 +119,12 @@ class ProfileHeaderView: UIView { let request = Client.getRelationships(accounts: [accountID]) mastodonController.run(request) { [weak self] (response) in - guard let self = self, + guard let mastodonController = self?.mastodonController, case let .success(results, _) = response, let relationship = results.first else { return } - self.mastodonController.persistentContainer.addOrUpdate(relationship: relationship) + mastodonController.persistentContainer.addOrUpdate(relationship: relationship) } }