From 112b5c3b109e6c9a8c5ab3101567e250da53b1fe Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Thu, 25 Oct 2018 08:00:12 +0530 Subject: [PATCH] Tunnel editing: Separate init for creation and modification Signed-off-by: Roopesh Chander --- .../UI/iOS/TunnelEditTableViewController.swift | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift index e3efc50..1c863f5 100644 --- a/WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift @@ -29,10 +29,21 @@ class TunnelEditTableViewController: UITableViewController { let tunnel: TunnelContainer? let tunnelViewModel: TunnelViewModel - init(tunnelsManager tm: TunnelsManager, tunnel t: TunnelContainer? = nil) { + init(tunnelsManager tm: TunnelsManager, tunnel t: TunnelContainer) { + // Use this initializer to edit an existing tunnel. tunnelsManager = tm tunnel = t - tunnelViewModel = TunnelViewModel(tunnelConfiguration: t?.tunnelConfiguration) + tunnelViewModel = TunnelViewModel(tunnelConfiguration: t.tunnelConfiguration) + super.init(style: .grouped) + self.modalPresentationStyle = .formSheet + } + + init(tunnelsManager tm: TunnelsManager, tunnelConfiguration: TunnelConfiguration?) { + // Use this initializer to create a new tunnel. + // If tunnelConfiguration is passed, data will be prepopulated from that configuration. + tunnelsManager = tm + tunnel = nil + tunnelViewModel = TunnelViewModel(tunnelConfiguration: tunnelConfiguration) super.init(style: .grouped) self.modalPresentationStyle = .formSheet }