From 5414f2329ca832a363f30913baadc736dddeb472 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 14 Oct 2020 19:34:30 -0400 Subject: [PATCH] Fix race condition causing My Profile tab bar image to not be set --- .../Profile/MyProfileViewController.swift | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Tusker/Screens/Profile/MyProfileViewController.swift b/Tusker/Screens/Profile/MyProfileViewController.swift index bf1945c5..e384cddf 100644 --- a/Tusker/Screens/Profile/MyProfileViewController.swift +++ b/Tusker/Screens/Profile/MyProfileViewController.swift @@ -7,6 +7,7 @@ // import UIKit +import Pachyderm class MyProfileViewController: ProfileViewController { @@ -21,7 +22,7 @@ class MyProfileViewController: ProfileViewController { DispatchQueue.main.async { self.accountID = account.id - self.setAvatarTabBarImage() + self.setAvatarTabBarImage(account: account) } } } @@ -38,12 +39,7 @@ class MyProfileViewController: ProfileViewController { NotificationCenter.default.addObserver(self, selector: #selector(preferencesChanged), name: .preferencesChanged, object: nil) } - private func setAvatarTabBarImage() { - guard let id = mastodonController.account?.id, - let account = mastodonController.persistentContainer.account(for: id) else { - return - } - + private func setAvatarTabBarImage(account: Account) { _ = ImageCache.avatars.get(account.avatar, completion: { [weak self] (data) in guard let self = self, let data = data, let image = UIImage(data: data) else { return } DispatchQueue.main.async { @@ -61,7 +57,12 @@ class MyProfileViewController: ProfileViewController { } @objc private func preferencesChanged() { - setAvatarTabBarImage() + guard let id = mastodonController.account?.id, + let account = mastodonController.persistentContainer.account(for: id) else { + return + } + + setAvatarTabBarImage(account: account) } // MARK: - Interaction