Fix retain cycles with TuskerNavigationDelegate

TuskerNavigationDelegate is now class-bound and only weak references to
it are stored.
This commit is contained in:
Shadowfacts 2020-01-19 23:02:07 -05:00
parent c45dd99088
commit 32e89f2c16
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
20 changed files with 28 additions and 29 deletions

View File

@ -8,7 +8,7 @@
import UIKit
protocol DraftsTableViewControllerDelegate {
protocol DraftsTableViewControllerDelegate: class {
func draftSelectionCanceled()
func shouldSelectDraft(_ draft: DraftsManager.Draft, completion: @escaping (Bool) -> Void)
func draftSelected(_ draft: DraftsManager.Draft)
@ -17,7 +17,7 @@ protocol DraftsTableViewControllerDelegate {
class DraftsTableViewController: UITableViewController {
var delegate: DraftsTableViewControllerDelegate?
weak var delegate: DraftsTableViewControllerDelegate?
init() {
super.init(nibName: "DraftsTableViewController", bundle: nil)

View File

@ -10,7 +10,7 @@ import UIKit
class MainTabBarViewController: UITabBarController, UITabBarControllerDelegate {
let mastodonController: MastodonController
weak var mastodonController: MastodonController!
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
if UIDevice.current.userInterfaceIdiom == .phone {

View File

@ -14,7 +14,7 @@ class NotificationsPageViewController: SegmentedPageViewController {
private let notificationsTitle = NSLocalizedString("Notifications", comment: "notifications tab title")
private let mentionsTitle = NSLocalizedString("Mentions", comment: "mentions tab title")
let mastodonController: MastodonController
weak var mastodonController: MastodonController!
init(mastodonController: MastodonController) {
self.mastodonController = mastodonController

View File

@ -10,7 +10,7 @@ import UIKit
import Combine
import Pachyderm
protocol InstanceSelectorTableViewControllerDelegate {
protocol InstanceSelectorTableViewControllerDelegate: class {
func didSelectInstance(url: URL)
}
@ -18,7 +18,7 @@ fileprivate let instanceCell = "instanceCell"
class InstanceSelectorTableViewController: UITableViewController {
var delegate: InstanceSelectorTableViewControllerDelegate?
weak var delegate: InstanceSelectorTableViewControllerDelegate?
var dataSource: DataSource!
var searchController: UISearchController!
@ -55,7 +55,7 @@ class InstanceSelectorTableViewController: UITableViewController {
tableView.rowHeight = UITableView.automaticDimension
tableView.estimatedRowHeight = 120
dataSource = DataSource(tableView: tableView, cellProvider: { (tableView, indexPath, item) -> UITableViewCell? in
dataSource = DataSource(tableView: tableView, cellProvider: { [weak self] (tableView, indexPath, item) -> UITableViewCell? in
switch item {
case let .selected(instance):
let cell = tableView.dequeueReusableCell(withIdentifier: instanceCell, for: indexPath) as! InstanceTableViewCell

View File

@ -12,7 +12,7 @@ import SafariServices
class ProfileTableViewController: EnhancedTableViewController {
let mastodonController: MastodonController
weak var mastodonController: MastodonController!
var accountID: String! {
didSet {

View File

@ -8,14 +8,14 @@
import UIKit
protocol InstanceTimelineViewControllerDelegate {
protocol InstanceTimelineViewControllerDelegate: class {
func didSaveInstance(url: URL)
func didUnsaveInstance(url: URL)
}
class InstanceTimelineViewController: TimelineTableViewController {
var delegate: InstanceTimelineViewControllerDelegate?
weak var delegate: InstanceTimelineViewControllerDelegate?
let instanceURL: URL

View File

@ -12,7 +12,7 @@ import Pachyderm
class TimelineTableViewController: EnhancedTableViewController {
var timeline: Timeline!
let mastodonController: MastodonController
weak var mastodonController: MastodonController!
var timelineSegments: [[(id: String, state: StatusState)]] = [] {
didSet {

View File

@ -14,7 +14,7 @@ class TimelinesPageViewController: SegmentedPageViewController {
private let federatedTitle = NSLocalizedString("Federated", comment: "federated timeline tab title")
private let localTitle = NSLocalizedString("Local", comment: "local timeline tab title")
let mastodonController: MastodonController
weak var mastodonController: MastodonController!
init(mastodonController: MastodonController) {
self.mastodonController = mastodonController

View File

@ -10,7 +10,7 @@ import UIKit
import SafariServices
import Pachyderm
protocol TuskerNavigationDelegate {
protocol TuskerNavigationDelegate: class {
var apiController: MastodonController { get }

View File

@ -10,7 +10,7 @@ import UIKit
class AccountTableViewCell: UITableViewCell {
var delegate: TuskerNavigationDelegate?
weak var delegate: TuskerNavigationDelegate?
var mastodonController: MastodonController! { delegate?.apiController }
@IBOutlet weak var avatarImageView: UIImageView!

View File

@ -11,13 +11,13 @@ import Pachyderm
import Gifu
import AVFoundation
protocol AttachmentViewDelegate {
protocol AttachmentViewDelegate: class {
func showAttachmentsGallery(startingAt index: Int)
}
class AttachmentView: UIImageView, GIFAnimatable {
var delegate: AttachmentViewDelegate?
weak var delegate: AttachmentViewDelegate?
var playImageView: UIImageView!
@ -71,8 +71,8 @@ class AttachmentView: UIImageView, GIFAnimatable {
}
func loadImage() {
ImageCache.attachments.get(attachment.url) { (data) in
guard let data = data else { return }
ImageCache.attachments.get(attachment.url) { [weak self] (data) in
guard let self = self, let data = data else { return }
DispatchQueue.main.async {
if self.attachment.url.pathExtension == "gif" {
self.animate(withGIFData: data)

View File

@ -11,7 +11,7 @@ import Pachyderm
class AttachmentsContainerView: UIView {
var delegate: AttachmentViewDelegate?
weak var delegate: AttachmentViewDelegate?
var statusID: String!
var attachments: [Attachment]!

View File

@ -10,14 +10,14 @@ import UIKit
import Photos
import AVFoundation
protocol ComposeMediaViewDelegate {
protocol ComposeMediaViewDelegate: class {
func didRemoveMedia(_ mediaView: ComposeMediaView)
func descriptionTextViewDidChange(_ mediaView: ComposeMediaView)
}
class ComposeMediaView: UIView {
var delegate: ComposeMediaViewDelegate?
weak var delegate: ComposeMediaViewDelegate?
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var descriptionTextView: UITextView!

View File

@ -15,8 +15,7 @@ private let emojiRegex = try! NSRegularExpression(pattern: ":(\\w+):", options:
class ContentTextView: LinkTextView {
// todo: should be weak
var navigationDelegate: TuskerNavigationDelegate?
weak var navigationDelegate: TuskerNavigationDelegate?
var mastodonController: MastodonController? { navigationDelegate?.apiController }
var defaultFont: UIFont = .systemFont(ofSize: 17)

View File

@ -11,7 +11,7 @@ import Pachyderm
class HashtagTableViewCell: UITableViewCell {
var delegate: TuskerNavigationDelegate?
weak var delegate: TuskerNavigationDelegate?
@IBOutlet weak var hashtagLabel: UILabel!

View File

@ -12,7 +12,7 @@ import SwiftSoup
class ActionNotificationGroupTableViewCell: UITableViewCell {
var delegate: TuskerNavigationDelegate?
weak var delegate: TuskerNavigationDelegate?
var mastodonController: MastodonController! { delegate?.apiController }
@IBOutlet weak var actionImageView: UIImageView!

View File

@ -11,7 +11,7 @@ import Pachyderm
class FollowNotificationGroupTableViewCell: UITableViewCell {
var delegate: TuskerNavigationDelegate?
weak var delegate: TuskerNavigationDelegate?
var mastodonController: MastodonController! { delegate?.apiController }
@IBOutlet weak var avatarStackView: UIStackView!

View File

@ -11,7 +11,7 @@ import Pachyderm
class FollowRequestNotificationTableViewCell: UITableViewCell {
var delegate: TuskerNavigationDelegate?
weak var delegate: TuskerNavigationDelegate?
var mastodonController: MastodonController! { delegate?.apiController }
@IBOutlet weak var stackView: UIStackView!

View File

@ -15,7 +15,7 @@ protocol ProfileHeaderTableViewCellDelegate: TuskerNavigationDelegate {
class ProfileHeaderTableViewCell: UITableViewCell {
var delegate: ProfileHeaderTableViewCellDelegate?
weak var delegate: ProfileHeaderTableViewCellDelegate?
var mastodonController: MastodonController! { delegate?.apiController }
@IBOutlet weak var headerImageView: UIImageView!

View File

@ -16,7 +16,7 @@ protocol StatusTableViewCellDelegate: TuskerNavigationDelegate {
class BaseStatusTableViewCell: UITableViewCell {
var delegate: StatusTableViewCellDelegate? {
weak var delegate: StatusTableViewCellDelegate? {
didSet {
contentTextView.navigationDelegate = delegate
}