From b6ad3f39e0d131eb60b7b2669d661ba3fd00929f Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Tue, 22 Jan 2019 19:57:35 +0530 Subject: [PATCH] macOS: reload: Iterate in reverse --- WireGuard/WireGuard/Tunnel/TunnelsManager.swift | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift index 28b6969..82d10a3 100644 --- a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift +++ b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift @@ -61,13 +61,11 @@ class TunnelsManager { let loadedTunnelProviders = managers ?? [] - var numberOfRemovedTunnels = 0 - for (index, currentTunnel) in self.tunnels.enumerated() { + for (index, currentTunnel) in self.tunnels.enumerated().reversed() { if !loadedTunnelProviders.contains(where: { $0.tunnelConfiguration == currentTunnel.tunnelConfiguration }) { // Tunnel was deleted outside the app - self.tunnels.remove(at: index - numberOfRemovedTunnels) - self.tunnelsListDelegate?.tunnelRemoved(at: index - numberOfRemovedTunnels) - numberOfRemovedTunnels += 1 + self.tunnels.remove(at: index) + self.tunnelsListDelegate?.tunnelRemoved(at: index) } } for loadedTunnelProvider in loadedTunnelProviders {