Skip to content

Commit

Permalink
Remove observer from DataBrokerProtectionViewController (#2057)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/1204167627774280/1206330267205340/f

**Description**:
Remove observer when DBP view is deallocated
  • Loading branch information
Bunn authored Jan 12, 2024
1 parent 9719e2b commit df75a55
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ final public class DataBrokerProtectionViewController: NSViewController {
private let webUIViewModel: DBPUIViewModel

private let openURLHandler: (URL?) -> Void
private var reloadObserver: NSObjectProtocol?

public init(scheduler: DataBrokerProtectionScheduler,
dataManager: DataBrokerProtectionDataManaging,
Expand Down Expand Up @@ -62,7 +63,7 @@ final public class DataBrokerProtectionViewController: NSViewController {
public override func viewDidLoad() {
super.viewDidLoad()

NotificationCenter.default.addObserver(forName: DataBrokerProtectionNotifications.shouldReloadUI,
reloadObserver = NotificationCenter.default.addObserver(forName: DataBrokerProtectionNotifications.shouldReloadUI,
object: nil,
queue: .main) { [weak self] _ in
self?.webView?.reload()
Expand All @@ -83,6 +84,12 @@ final public class DataBrokerProtectionViewController: NSViewController {
}

}

deinit {
if let reloadObserver {
NotificationCenter.default.removeObserver(reloadObserver)
}
}
}

extension DataBrokerProtectionViewController: WKUIDelegate {
Expand Down

0 comments on commit df75a55

Please sign in to comment.