From 08025a56e47a312841e013b0a227709fb747d6bb Mon Sep 17 00:00:00 2001 From: Juraj Hilje Date: Wed, 30 Sep 2020 08:35:04 +0200 Subject: [PATCH 1/2] refactor(unneeded_notification_center_removal): fix Unneeded NotificationCenter Removal Violation warning --- IVPNClient/Managers/VPNErrorObserver.swift | 1 - .../AccountScreen/AccountViewController.swift | 8 -------- .../ControlPanelViewController.swift | 19 ------------------- .../MainScreen/MainViewController.swift | 7 ------- .../Scenes/MainScreen/Map/MapMarkerView.swift | 14 -------------- .../Scenes/MainScreen/Map/MapScrollView.swift | 10 ---------- .../Scenes/MainScreen/View/MainView.swift | 8 -------- .../Scenes/Signup/LoginViewController.swift | 12 ------------ .../Scanner/ScannerViewController.swift | 4 ---- .../NetworkProtectionViewController.swift | 4 ---- .../SettingsViewController.swift | 11 ----------- 11 files changed, 98 deletions(-) diff --git a/IVPNClient/Managers/VPNErrorObserver.swift b/IVPNClient/Managers/VPNErrorObserver.swift index ee1d6f42f..4ac099fbd 100644 --- a/IVPNClient/Managers/VPNErrorObserver.swift +++ b/IVPNClient/Managers/VPNErrorObserver.swift @@ -42,7 +42,6 @@ class VPNErrorObserver { } deinit { - NotificationCenter.default.removeObserver(self, name: Notification.Name.VPNConnectError, object: nil) wireguardErrorObserver?.invalidate() wireguardErrorObserver = nil } diff --git a/IVPNClient/Scenes/AccountScreen/AccountViewController.swift b/IVPNClient/Scenes/AccountScreen/AccountViewController.swift index 221cb362d..01a4ea642 100644 --- a/IVPNClient/Scenes/AccountScreen/AccountViewController.swift +++ b/IVPNClient/Scenes/AccountScreen/AccountViewController.swift @@ -69,20 +69,12 @@ class AccountViewController: UITableViewController { accountView.initQRCode(viewModel: viewModel) } - deinit { - removeObservers() - } - // MARK: - Observers - func addObservers() { NotificationCenter.default.addObserver(self, selector: #selector(subscriptionActivated), name: Notification.Name.SubscriptionActivated, object: nil) } - func removeObservers() { - NotificationCenter.default.removeObserver(self, name: Notification.Name.SubscriptionActivated, object: nil) - } - // MARK: - Private methods - private func initNavigationBar() { diff --git a/IVPNClient/Scenes/MainScreen/ControlPanel/ControlPanelViewController.swift b/IVPNClient/Scenes/MainScreen/ControlPanel/ControlPanelViewController.swift index 63cf92b71..7f266d5c8 100644 --- a/IVPNClient/Scenes/MainScreen/ControlPanel/ControlPanelViewController.swift +++ b/IVPNClient/Scenes/MainScreen/ControlPanel/ControlPanelViewController.swift @@ -142,10 +142,6 @@ class ControlPanelViewController: UITableViewController { NotificationCenter.default.removeObserver(self, name: Notification.Name.PingDidComplete, object: nil) } - deinit { - removeObservers() - } - // MARK: - Gestures - private func setupGestureRecognizers() { @@ -372,21 +368,6 @@ class ControlPanelViewController: UITableViewController { NotificationCenter.default.addObserver(self, selector: #selector(protocolSelected), name: Notification.Name.ProtocolSelected, object: nil) } - private func removeObservers() { - NotificationCenter.default.removeObserver(self, name: Notification.Name.UpdateControlPanel, object: nil) - NotificationCenter.default.removeObserver(self, name: Notification.Name.ServerSelected, object: nil) - NotificationCenter.default.removeObserver(self, name: Notification.Name.Connect, object: nil) - NotificationCenter.default.removeObserver(self, name: Notification.Name.Disconnect, object: nil) - NotificationCenter.default.removeObserver(self, name: Notification.Name.AuthenticationDismissed, object: nil) - NotificationCenter.default.removeObserver(self, name: Notification.Name.SubscriptionDismissed, object: nil) - NotificationCenter.default.removeObserver(self, name: Notification.Name.ServiceAuthorized, object: nil) - NotificationCenter.default.removeObserver(self, name: Notification.Name.SubscriptionActivated, object: nil) - NotificationCenter.default.removeObserver(self, name: Notification.Name.NewSession, object: nil) - NotificationCenter.default.removeObserver(self, name: Notification.Name.ForceNewSession, object: nil) - NotificationCenter.default.removeObserver(self, name: Notification.Name.ProtocolSelected, object: nil) - NotificationCenter.default.removeObserver(self, name: Notification.Name.TermsOfServiceAgreed, object: nil) - } - // MARK: - Private methods - private func initView() { diff --git a/IVPNClient/Scenes/MainScreen/MainViewController.swift b/IVPNClient/Scenes/MainScreen/MainViewController.swift index 7b28f916b..9eaf97cd2 100644 --- a/IVPNClient/Scenes/MainScreen/MainViewController.swift +++ b/IVPNClient/Scenes/MainScreen/MainViewController.swift @@ -84,7 +84,6 @@ class MainViewController: UIViewController { } deinit { - removeObservers() updateServersTimer.invalidate() Application.shared.connectionManager.removeStatusChangeUpdates() } @@ -172,12 +171,6 @@ class MainViewController: UIViewController { NotificationCenter.default.addObserver(self, selector: #selector(subscriptionActivated), name: Notification.Name.SubscriptionActivated, object: nil) } - private func removeObservers() { - NotificationCenter.default.removeObserver(self, name: Notification.Name.UpdateFloatingPanelLayout, object: nil) - NotificationCenter.default.removeObserver(self, name: Notification.Name.VPNConfigurationDisabled, object: nil) - NotificationCenter.default.removeObserver(self, name: Notification.Name.SubscriptionActivated, object: nil) - } - // MARK: - Private methods - @objc private func updateFloatingPanelLayout() { diff --git a/IVPNClient/Scenes/MainScreen/Map/MapMarkerView.swift b/IVPNClient/Scenes/MainScreen/Map/MapMarkerView.swift index b6791f0f6..9b55da266 100644 --- a/IVPNClient/Scenes/MainScreen/Map/MapMarkerView.swift +++ b/IVPNClient/Scenes/MainScreen/Map/MapMarkerView.swift @@ -106,10 +106,6 @@ class MapMarkerView: UIView { super.updateConstraints() } - deinit { - removeObservers() - } - // MARK: - Methods - func updateCircles(color: UIColor) { @@ -166,16 +162,6 @@ class MapMarkerView: UIView { } } - private func removeObservers() { - NotificationCenter.default.removeObserver(self, name: Notification.Name.HideConnectionInfoPopup, object: nil) - - if #available(iOS 13.0, *) { - NotificationCenter.default.removeObserver(self, name: UIScene.didActivateNotification, object: nil) - } else { - NotificationCenter.default.removeObserver(self, name: UIApplication.didBecomeActiveNotification, object: nil) - } - } - // MARK: - Private methods - private func setupConstraints() { diff --git a/IVPNClient/Scenes/MainScreen/Map/MapScrollView.swift b/IVPNClient/Scenes/MainScreen/Map/MapScrollView.swift index a52932e8c..25de62288 100644 --- a/IVPNClient/Scenes/MainScreen/Map/MapScrollView.swift +++ b/IVPNClient/Scenes/MainScreen/Map/MapScrollView.swift @@ -72,10 +72,6 @@ class MapScrollView: UIScrollView { addObservers() } - deinit { - removeObservers() - } - // MARK: - Methods - func setupConstraints() { @@ -146,12 +142,6 @@ class MapScrollView: UIScrollView { NotificationCenter.default.addObserver(self, selector: #selector(hideConnectToServerPopup), name: Notification.Name.HideConnectToServerPopup, object: nil) } - private func removeObservers() { - NotificationCenter.default.removeObserver(self, name: Notification.Name.ServerSelected, object: nil) - NotificationCenter.default.removeObserver(self, name: Notification.Name.PingDidComplete, object: nil) - NotificationCenter.default.removeObserver(self, name: Notification.Name.HideConnectToServerPopup, object: nil) - } - private func initGestures() { let tap = UITapGestureRecognizer(target: self, action: #selector(handleTap)) addGestureRecognizer(tap) diff --git a/IVPNClient/Scenes/MainScreen/View/MainView.swift b/IVPNClient/Scenes/MainScreen/View/MainView.swift index b3ee86093..e4a65c8ef 100644 --- a/IVPNClient/Scenes/MainScreen/View/MainView.swift +++ b/IVPNClient/Scenes/MainScreen/View/MainView.swift @@ -65,10 +65,6 @@ class MainView: UIView { } } - deinit { - removeObservers() - } - // MARK: - Methods - func setupView(animated: Bool = true) { @@ -100,10 +96,6 @@ class MainView: UIView { NotificationCenter.default.addObserver(self, selector: #selector(centerMap), name: Notification.Name.CenterMap, object: nil) } - private func removeObservers() { - NotificationCenter.default.removeObserver(self, name: Notification.Name.CenterMap, object: nil) - } - private func initSettingsAction() { let settingsButton = UIButton() addSubview(settingsButton) diff --git a/IVPNClient/Scenes/Signup/LoginViewController.swift b/IVPNClient/Scenes/Signup/LoginViewController.swift index ac0dac750..293aa859c 100644 --- a/IVPNClient/Scenes/Signup/LoginViewController.swift +++ b/IVPNClient/Scenes/Signup/LoginViewController.swift @@ -122,10 +122,6 @@ class LoginViewController: UIViewController { } } - deinit { - removeObservers() - } - // MARK: - Observers - func addObservers() { @@ -134,14 +130,6 @@ class LoginViewController: UIViewController { NotificationCenter.default.addObserver(self, selector: #selector(termsOfServiceAgreed), name: Notification.Name.TermsOfServiceAgreed, object: nil) } - func removeObservers() { - NotificationCenter.default.removeObserver(self, name: Notification.Name.SubscriptionDismissed, object: nil) - NotificationCenter.default.removeObserver(self, name: Notification.Name.SubscriptionActivated, object: nil) - NotificationCenter.default.removeObserver(self, name: Notification.Name.NewSession, object: nil) - NotificationCenter.default.removeObserver(self, name: Notification.Name.ForceNewSession, object: nil) - NotificationCenter.default.removeObserver(self, name: Notification.Name.TermsOfServiceAgreed, object: nil) - } - @objc func newSession() { startLoginProcess() } diff --git a/IVPNClient/Scenes/Signup/Scanner/ScannerViewController.swift b/IVPNClient/Scenes/Signup/Scanner/ScannerViewController.swift index 6a08d727c..eac8a3235 100644 --- a/IVPNClient/Scenes/Signup/Scanner/ScannerViewController.swift +++ b/IVPNClient/Scenes/Signup/Scanner/ScannerViewController.swift @@ -67,10 +67,6 @@ class ScannerViewController: UIViewController, AVCaptureMetadataOutputObjectsDel stopCaptureSession() } - deinit { - NotificationCenter.default.removeObserver(self, name: UIDevice.orientationDidChangeNotification, object: nil) - } - // MARK: - Orientation - override var supportedInterfaceOrientations: UIInterfaceOrientationMask { diff --git a/IVPNClient/Scenes/ViewControllers/NetworkProtectionViewController.swift b/IVPNClient/Scenes/ViewControllers/NetworkProtectionViewController.swift index 9b80934f2..dee2d4d7e 100644 --- a/IVPNClient/Scenes/ViewControllers/NetworkProtectionViewController.swift +++ b/IVPNClient/Scenes/ViewControllers/NetworkProtectionViewController.swift @@ -51,10 +51,6 @@ class NetworkProtectionViewController: UITableViewController { NotificationCenter.default.addObserver(self, selector: #selector(loadHandler), name: Notification.Name.NetworkSaved, object: nil) } - deinit { - NotificationCenter.default.removeObserver(self) - } - // MARK: - Interface Orientations - override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { diff --git a/IVPNClient/Scenes/ViewControllers/SettingsViewController.swift b/IVPNClient/Scenes/ViewControllers/SettingsViewController.swift index d511cf40a..006fa0991 100644 --- a/IVPNClient/Scenes/ViewControllers/SettingsViewController.swift +++ b/IVPNClient/Scenes/ViewControllers/SettingsViewController.swift @@ -236,10 +236,6 @@ class SettingsViewController: UITableViewController { NotificationCenter.default.removeObserver(self, name: Notification.Name.PingDidComplete, object: nil) } - deinit { - removeObservers() - } - // MARK: - Segues - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { @@ -304,13 +300,6 @@ class SettingsViewController: UITableViewController { NotificationCenter.default.addObserver(self, selector: #selector(authenticationDismissed), name: Notification.Name.AuthenticationDismissed, object: nil) } - func removeObservers() { - NotificationCenter.default.removeObserver(self, name: Notification.Name.TurnOffMultiHop, object: nil) - NotificationCenter.default.removeObserver(self, name: Notification.Name.TermsOfServiceAgreed, object: nil) - NotificationCenter.default.removeObserver(self, name: Notification.Name.ServiceAuthorized, object: nil) - NotificationCenter.default.removeObserver(self, name: Notification.Name.AuthenticationDismissed, object: nil) - } - @objc func turnOffMultiHop() { UserDefaults.shared.set(false, forKey: UserDefaults.Key.isMultiHop) multiHopSwitch.setOn(false, animated: false) From 2aa299972e9d9667138b28230e376c08a2bb9cfb Mon Sep 17 00:00:00 2001 From: Juraj Hilje Date: Wed, 30 Sep 2020 08:46:09 +0200 Subject: [PATCH 2/2] refactor: fix Colons should be next to the identifier warning --- IVPNClient/Scenes/Signup/Scanner/ScannerViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IVPNClient/Scenes/Signup/Scanner/ScannerViewController.swift b/IVPNClient/Scenes/Signup/Scanner/ScannerViewController.swift index eac8a3235..cafe3c3b5 100644 --- a/IVPNClient/Scenes/Signup/Scanner/ScannerViewController.swift +++ b/IVPNClient/Scenes/Signup/Scanner/ScannerViewController.swift @@ -160,7 +160,7 @@ class ScannerViewController: UIViewController, AVCaptureMetadataOutputObjectsDel } private func allowCameraAccessViaSetting() { - showActionAlert(title: "Allow Camera", message: "Camera access is required to scan QR code", action: "Open Settings", actionHandler: { _ in + showActionAlert(title: "Allow Camera", message: "Camera access is required to scan QR code", action: "Open Settings", actionHandler: { _ in if let url = URL(string: UIApplication.openSettingsURLString) { UIApplication.shared.open(url) }