From 038e4b2e4e0e57cd7fa4cc53bcb79b26d5ff6af7 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 14 May 2023 18:24:21 -0400 Subject: [PATCH] Fix crash when action notification cell label leaks --- .../ActionNotificationGroupCollectionViewCell.swift | 2 +- Tusker/Views/MultiSourceEmojiLabel.swift | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Tusker/Screens/Notifications/ActionNotificationGroupCollectionViewCell.swift b/Tusker/Screens/Notifications/ActionNotificationGroupCollectionViewCell.swift index da79272e..2a11af32 100644 --- a/Tusker/Screens/Notifications/ActionNotificationGroupCollectionViewCell.swift +++ b/Tusker/Screens/Notifications/ActionNotificationGroupCollectionViewCell.swift @@ -60,7 +60,7 @@ class ActionNotificationGroupCollectionViewCell: UICollectionViewListCell { $0.adjustsFontForContentSizeCategory = true $0.numberOfLines = 2 $0.lineBreakMode = .byTruncatingTail - $0.combiner = { [unowned self] in self.updateActionLabel(names: $0) } + $0.combiner = { [weak self] in self?.updateActionLabel(names: $0) ?? NSAttributedString() } } private let statusContentLabel = UILabel().configure { diff --git a/Tusker/Views/MultiSourceEmojiLabel.swift b/Tusker/Views/MultiSourceEmojiLabel.swift index 1b682121..e6978801 100644 --- a/Tusker/Views/MultiSourceEmojiLabel.swift +++ b/Tusker/Views/MultiSourceEmojiLabel.swift @@ -24,21 +24,18 @@ class MultiSourceEmojiLabel: UILabel, BaseEmojiLabel { var attributedStrings = pairs.map { NSAttributedString(string: $0.0) } - func recombine() { - if let combiner = self.combiner { + let recombine = { [weak self] in + if let self, + let combiner = self.combiner { self.attributedText = combiner(attributedStrings) } } - recombine() for (index, (string, emojis)) in pairs.enumerated() { self.replaceEmojis(in: string, emojis: emojis, identifier: identifier) { (attributedString, _) in attributedStrings[index] = attributedString - DispatchQueue.main.async { [weak self] in - guard let self else { return } - recombine() - } + DispatchQueue.main.async(execute: recombine) } } }