diff --git a/Tusker/Screens/Compose/Drafts/DraftsTableViewController.swift b/Tusker/Screens/Compose/Drafts/DraftsTableViewController.swift index 3f71e3f2..40f90faa 100644 --- a/Tusker/Screens/Compose/Drafts/DraftsTableViewController.swift +++ b/Tusker/Screens/Compose/Drafts/DraftsTableViewController.swift @@ -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) diff --git a/Tusker/Screens/Main/MainTabBarViewController.swift b/Tusker/Screens/Main/MainTabBarViewController.swift index dd49bcae..932a257a 100644 --- a/Tusker/Screens/Main/MainTabBarViewController.swift +++ b/Tusker/Screens/Main/MainTabBarViewController.swift @@ -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 { diff --git a/Tusker/Screens/Notifications/NotificationsPageViewController.swift b/Tusker/Screens/Notifications/NotificationsPageViewController.swift index ac66701a..6a23f5c6 100644 --- a/Tusker/Screens/Notifications/NotificationsPageViewController.swift +++ b/Tusker/Screens/Notifications/NotificationsPageViewController.swift @@ -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 diff --git a/Tusker/Screens/Onboarding/InstanceSelectorTableViewController.swift b/Tusker/Screens/Onboarding/InstanceSelectorTableViewController.swift index 0be76809..11681d23 100644 --- a/Tusker/Screens/Onboarding/InstanceSelectorTableViewController.swift +++ b/Tusker/Screens/Onboarding/InstanceSelectorTableViewController.swift @@ -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 diff --git a/Tusker/Screens/Profile/ProfileTableViewController.swift b/Tusker/Screens/Profile/ProfileTableViewController.swift index 8ff37b65..ee7a9cac 100644 --- a/Tusker/Screens/Profile/ProfileTableViewController.swift +++ b/Tusker/Screens/Profile/ProfileTableViewController.swift @@ -12,7 +12,7 @@ import SafariServices class ProfileTableViewController: EnhancedTableViewController { - let mastodonController: MastodonController + weak var mastodonController: MastodonController! var accountID: String! { didSet { diff --git a/Tusker/Screens/Timeline/InstanceTimelineViewController.swift b/Tusker/Screens/Timeline/InstanceTimelineViewController.swift index ff809ba7..d5c19430 100644 --- a/Tusker/Screens/Timeline/InstanceTimelineViewController.swift +++ b/Tusker/Screens/Timeline/InstanceTimelineViewController.swift @@ -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 diff --git a/Tusker/Screens/Timeline/TimelineTableViewController.swift b/Tusker/Screens/Timeline/TimelineTableViewController.swift index 12022b00..9966b510 100644 --- a/Tusker/Screens/Timeline/TimelineTableViewController.swift +++ b/Tusker/Screens/Timeline/TimelineTableViewController.swift @@ -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 { diff --git a/Tusker/Screens/Timeline/TimelinesPageViewController.swift b/Tusker/Screens/Timeline/TimelinesPageViewController.swift index a01e74db..19fb6878 100644 --- a/Tusker/Screens/Timeline/TimelinesPageViewController.swift +++ b/Tusker/Screens/Timeline/TimelinesPageViewController.swift @@ -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 diff --git a/Tusker/TuskerNavigationDelegate.swift b/Tusker/TuskerNavigationDelegate.swift index 8915fe16..41f39603 100644 --- a/Tusker/TuskerNavigationDelegate.swift +++ b/Tusker/TuskerNavigationDelegate.swift @@ -10,7 +10,7 @@ import UIKit import SafariServices import Pachyderm -protocol TuskerNavigationDelegate { +protocol TuskerNavigationDelegate: class { var apiController: MastodonController { get } diff --git a/Tusker/Views/Account Cell/AccountTableViewCell.swift b/Tusker/Views/Account Cell/AccountTableViewCell.swift index cb93b6bd..cf01f6ef 100644 --- a/Tusker/Views/Account Cell/AccountTableViewCell.swift +++ b/Tusker/Views/Account Cell/AccountTableViewCell.swift @@ -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! diff --git a/Tusker/Views/Attachments/AttachmentView.swift b/Tusker/Views/Attachments/AttachmentView.swift index e65b2d8d..41bfad86 100644 --- a/Tusker/Views/Attachments/AttachmentView.swift +++ b/Tusker/Views/Attachments/AttachmentView.swift @@ -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) diff --git a/Tusker/Views/Attachments/AttachmentsContainerView.swift b/Tusker/Views/Attachments/AttachmentsContainerView.swift index 5ca7deb9..d8e18f9c 100644 --- a/Tusker/Views/Attachments/AttachmentsContainerView.swift +++ b/Tusker/Views/Attachments/AttachmentsContainerView.swift @@ -11,7 +11,7 @@ import Pachyderm class AttachmentsContainerView: UIView { - var delegate: AttachmentViewDelegate? + weak var delegate: AttachmentViewDelegate? var statusID: String! var attachments: [Attachment]! diff --git a/Tusker/Views/Compose Media/ComposeMediaView.swift b/Tusker/Views/Compose Media/ComposeMediaView.swift index 54c1efd7..cd7ba31f 100644 --- a/Tusker/Views/Compose Media/ComposeMediaView.swift +++ b/Tusker/Views/Compose Media/ComposeMediaView.swift @@ -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! diff --git a/Tusker/Views/ContentTextView.swift b/Tusker/Views/ContentTextView.swift index ea700587..b36076dc 100644 --- a/Tusker/Views/ContentTextView.swift +++ b/Tusker/Views/ContentTextView.swift @@ -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) diff --git a/Tusker/Views/Hashtag Cell/HashtagTableViewCell.swift b/Tusker/Views/Hashtag Cell/HashtagTableViewCell.swift index bd364d16..3a9008cf 100644 --- a/Tusker/Views/Hashtag Cell/HashtagTableViewCell.swift +++ b/Tusker/Views/Hashtag Cell/HashtagTableViewCell.swift @@ -11,7 +11,7 @@ import Pachyderm class HashtagTableViewCell: UITableViewCell { - var delegate: TuskerNavigationDelegate? + weak var delegate: TuskerNavigationDelegate? @IBOutlet weak var hashtagLabel: UILabel! diff --git a/Tusker/Views/Notifications/ActionNotificationGroupTableViewCell.swift b/Tusker/Views/Notifications/ActionNotificationGroupTableViewCell.swift index cedde5f6..62256c38 100644 --- a/Tusker/Views/Notifications/ActionNotificationGroupTableViewCell.swift +++ b/Tusker/Views/Notifications/ActionNotificationGroupTableViewCell.swift @@ -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! diff --git a/Tusker/Views/Notifications/FollowNotificationGroupTableViewCell.swift b/Tusker/Views/Notifications/FollowNotificationGroupTableViewCell.swift index 0c2e62cc..0113d78e 100644 --- a/Tusker/Views/Notifications/FollowNotificationGroupTableViewCell.swift +++ b/Tusker/Views/Notifications/FollowNotificationGroupTableViewCell.swift @@ -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! diff --git a/Tusker/Views/Notifications/FollowRequestNotificationTableViewCell.swift b/Tusker/Views/Notifications/FollowRequestNotificationTableViewCell.swift index 1674c639..f62f71b1 100644 --- a/Tusker/Views/Notifications/FollowRequestNotificationTableViewCell.swift +++ b/Tusker/Views/Notifications/FollowRequestNotificationTableViewCell.swift @@ -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! diff --git a/Tusker/Views/Profile Header/ProfileHeaderTableViewCell.swift b/Tusker/Views/Profile Header/ProfileHeaderTableViewCell.swift index a3df7918..bf740fa5 100644 --- a/Tusker/Views/Profile Header/ProfileHeaderTableViewCell.swift +++ b/Tusker/Views/Profile Header/ProfileHeaderTableViewCell.swift @@ -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! diff --git a/Tusker/Views/Status/BaseStatusTableViewCell.swift b/Tusker/Views/Status/BaseStatusTableViewCell.swift index 0b7f778e..a34f8d09 100644 --- a/Tusker/Views/Status/BaseStatusTableViewCell.swift +++ b/Tusker/Views/Status/BaseStatusTableViewCell.swift @@ -16,7 +16,7 @@ protocol StatusTableViewCellDelegate: TuskerNavigationDelegate { class BaseStatusTableViewCell: UITableViewCell { - var delegate: StatusTableViewCellDelegate? { + weak var delegate: StatusTableViewCellDelegate? { didSet { contentTextView.navigationDelegate = delegate }