aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/iOS
diff options
context:
space:
mode:
authorEric Kuck <eric@bluelinelabs.com>2018-12-12 12:28:27 -0600
committerEric Kuck <eric@bluelinelabs.com>2018-12-12 12:28:27 -0600
commitd06cff2a360839c67ce42a695f01bb933ba820c0 (patch)
tree3aa166de8c75947345b9bfb8398ee8b7c6b581c7 /WireGuard/WireGuard/UI/iOS
parentAdded swiftlint and fixed all errors (and a bunch, but not all, warnings) (diff)
downloadwireguard-apple-d06cff2a360839c67ce42a695f01bb933ba820c0.tar.xz
wireguard-apple-d06cff2a360839c67ce42a695f01bb933ba820c0.zip
Tons more swiftlint warnings fixed. Still a few remaining.
Signed-off-by: Eric Kuck <eric@bluelinelabs.com>
Diffstat (limited to 'WireGuard/WireGuard/UI/iOS')
-rw-r--r--WireGuard/WireGuard/UI/iOS/AppDelegate.swift2
-rw-r--r--WireGuard/WireGuard/UI/iOS/MainViewController.swift2
-rw-r--r--WireGuard/WireGuard/UI/iOS/SettingsTableViewController.swift30
-rw-r--r--WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift68
-rw-r--r--WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift34
-rw-r--r--WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift22
6 files changed, 79 insertions, 79 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/AppDelegate.swift b/WireGuard/WireGuard/UI/iOS/AppDelegate.swift
index d62890e..1a4f15c 100644
--- a/WireGuard/WireGuard/UI/iOS/AppDelegate.swift
+++ b/WireGuard/WireGuard/UI/iOS/AppDelegate.swift
@@ -53,7 +53,7 @@ extension AppDelegate {
viewControllerWithRestorationIdentifierPath identifierComponents: [String],
coder: NSCoder) -> UIViewController? {
guard let vcIdentifier = identifierComponents.last else { return nil }
- if (vcIdentifier.hasPrefix("TunnelDetailVC:")) {
+ if vcIdentifier.hasPrefix("TunnelDetailVC:") {
let tunnelName = String(vcIdentifier.suffix(vcIdentifier.count - "TunnelDetailVC:".count))
if let tunnelsManager = mainVC?.tunnelsManager {
if let tunnel = tunnelsManager.tunnel(named: tunnelName) {
diff --git a/WireGuard/WireGuard/UI/iOS/MainViewController.swift b/WireGuard/WireGuard/UI/iOS/MainViewController.swift
index c06b5d3..70d838e 100644
--- a/WireGuard/WireGuard/UI/iOS/MainViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/MainViewController.swift
@@ -81,7 +81,7 @@ extension MainViewController {
let tunnelDetailNC = UINavigationController(rootViewController: tunnelDetailVC)
tunnelDetailNC.restorationIdentifier = "DetailNC"
if let self = self {
- if (animated) {
+ if animated {
self.showDetailViewController(tunnelDetailNC, sender: self)
} else {
UIView.performWithoutAnimation {
diff --git a/WireGuard/WireGuard/UI/iOS/SettingsTableViewController.swift b/WireGuard/WireGuard/UI/iOS/SettingsTableViewController.swift
index aade1df..3107579 100644
--- a/WireGuard/WireGuard/UI/iOS/SettingsTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/SettingsTableViewController.swift
@@ -40,8 +40,8 @@ class SettingsTableViewController: UITableViewController {
self.tableView.rowHeight = UITableView.automaticDimension
self.tableView.allowsSelection = false
- self.tableView.register(TunnelSettingsTableViewKeyValueCell.self, forCellReuseIdentifier: TunnelSettingsTableViewKeyValueCell.id)
- self.tableView.register(TunnelSettingsTableViewButtonCell.self, forCellReuseIdentifier: TunnelSettingsTableViewButtonCell.id)
+ self.tableView.register(TunnelSettingsTableViewKeyValueCell.self, forCellReuseIdentifier: TunnelSettingsTableViewKeyValueCell.reuseIdentifier)
+ self.tableView.register(TunnelSettingsTableViewButtonCell.self, forCellReuseIdentifier: TunnelSettingsTableViewButtonCell.reuseIdentifier)
let logo = UIImageView(image: UIImage(named: "wireguard.pdf", in: Bundle.main, compatibleWith: nil)!)
logo.contentMode = .scaleAspectFit
@@ -99,9 +99,9 @@ class SettingsTableViewController: UITableViewController {
DispatchQueue.global(qos: .userInitiated).async {
- if (FileManager.default.fileExists(atPath: destinationURL.path)) {
+ if FileManager.default.fileExists(atPath: destinationURL.path) {
let isDeleted = FileManager.deleteFile(at: destinationURL)
- if (!isDeleted) {
+ if !isDeleted {
ErrorPresenter.showErrorAlert(title: "No log available", message: "The pre-existing log could not be cleared", from: self)
return
}
@@ -149,7 +149,7 @@ extension SettingsTableViewController {
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
- switch (section) {
+ switch section {
case 0:
return "About"
case 1:
@@ -163,21 +163,21 @@ extension SettingsTableViewController {
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let field = settingsFieldsBySection[indexPath.section][indexPath.row]
- if (field == .iosAppVersion || field == .goBackendVersion) {
- let cell = tableView.dequeueReusableCell(withIdentifier: TunnelSettingsTableViewKeyValueCell.id, for: indexPath) as! TunnelSettingsTableViewKeyValueCell
+ if field == .iosAppVersion || field == .goBackendVersion {
+ let cell = tableView.dequeueReusableCell(withIdentifier: TunnelSettingsTableViewKeyValueCell.reuseIdentifier, for: indexPath) as! TunnelSettingsTableViewKeyValueCell
cell.key = field.rawValue
- if (field == .iosAppVersion) {
+ if field == .iosAppVersion {
var appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "Unknown version"
if let appBuild = Bundle.main.infoDictionary?["CFBundleVersion"] as? String {
appVersion += " (\(appBuild))"
}
cell.value = appVersion
- } else if (field == .goBackendVersion) {
+ } else if field == .goBackendVersion {
cell.value = WIREGUARD_GO_VERSION
}
return cell
- } else if (field == .exportZipArchive) {
- let cell = tableView.dequeueReusableCell(withIdentifier: TunnelSettingsTableViewButtonCell.id, for: indexPath) as! TunnelSettingsTableViewButtonCell
+ } else if field == .exportZipArchive {
+ let cell = tableView.dequeueReusableCell(withIdentifier: TunnelSettingsTableViewButtonCell.reuseIdentifier, for: indexPath) as! TunnelSettingsTableViewButtonCell
cell.buttonText = field.rawValue
cell.onTapped = { [weak self] in
self?.exportConfigurationsAsZipFile(sourceView: cell.button)
@@ -185,7 +185,7 @@ extension SettingsTableViewController {
return cell
} else {
assert(field == .exportLogFile)
- let cell = tableView.dequeueReusableCell(withIdentifier: TunnelSettingsTableViewButtonCell.id, for: indexPath) as! TunnelSettingsTableViewButtonCell
+ let cell = tableView.dequeueReusableCell(withIdentifier: TunnelSettingsTableViewButtonCell.reuseIdentifier, for: indexPath) as! TunnelSettingsTableViewButtonCell
cell.buttonText = field.rawValue
cell.onTapped = { [weak self] in
self?.exportLogForLastActivatedTunnel(sourceView: cell.button)
@@ -196,7 +196,7 @@ extension SettingsTableViewController {
}
class TunnelSettingsTableViewKeyValueCell: UITableViewCell {
- static let id: String = "TunnelSettingsTableViewKeyValueCell"
+ static let reuseIdentifier = "TunnelSettingsTableViewKeyValueCell"
var key: String {
get { return textLabel?.text ?? "" }
set(value) { textLabel?.text = value }
@@ -207,7 +207,7 @@ class TunnelSettingsTableViewKeyValueCell: UITableViewCell {
}
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
- super.init(style: .value1, reuseIdentifier: TunnelSettingsTableViewKeyValueCell.id)
+ super.init(style: .value1, reuseIdentifier: TunnelSettingsTableViewKeyValueCell.reuseIdentifier)
}
required init?(coder aDecoder: NSCoder) {
@@ -222,7 +222,7 @@ class TunnelSettingsTableViewKeyValueCell: UITableViewCell {
}
class TunnelSettingsTableViewButtonCell: UITableViewCell {
- static let id: String = "TunnelSettingsTableViewButtonCell"
+ static let reuseIdentifier = "TunnelSettingsTableViewButtonCell"
var buttonText: String {
get { return button.title(for: .normal) ?? "" }
set(value) { button.setTitle(value, for: .normal) }
diff --git a/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift
index b54efd9..2ab3c26 100644
--- a/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift
@@ -40,10 +40,10 @@ class TunnelDetailTableViewController: UITableViewController {
self.tableView.estimatedRowHeight = 44
self.tableView.rowHeight = UITableView.automaticDimension
self.tableView.allowsSelection = false
- self.tableView.register(TunnelDetailTableViewStatusCell.self, forCellReuseIdentifier: TunnelDetailTableViewStatusCell.id)
- self.tableView.register(TunnelDetailTableViewKeyValueCell.self, forCellReuseIdentifier: TunnelDetailTableViewKeyValueCell.id)
- self.tableView.register(TunnelDetailTableViewButtonCell.self, forCellReuseIdentifier: TunnelDetailTableViewButtonCell.id)
- self.tableView.register(TunnelDetailTableViewActivateOnDemandCell.self, forCellReuseIdentifier: TunnelDetailTableViewActivateOnDemandCell.id)
+ self.tableView.register(TunnelDetailTableViewStatusCell.self, forCellReuseIdentifier: TunnelDetailTableViewStatusCell.reuseIdentifier)
+ self.tableView.register(TunnelDetailTableViewKeyValueCell.self, forCellReuseIdentifier: TunnelDetailTableViewKeyValueCell.reuseIdentifier)
+ self.tableView.register(TunnelDetailTableViewButtonCell.self, forCellReuseIdentifier: TunnelDetailTableViewButtonCell.reuseIdentifier)
+ self.tableView.register(TunnelDetailTableViewActivateOnDemandCell.self, forCellReuseIdentifier: TunnelDetailTableViewActivateOnDemandCell.reuseIdentifier)
// State restoration
self.restorationIdentifier = "TunnelDetailVC:\(tunnel.name)"
@@ -99,17 +99,17 @@ extension TunnelDetailTableViewController {
let interfaceData = tunnelViewModel.interfaceData
let numberOfPeerSections = tunnelViewModel.peersData.count
- if (section == 0) {
+ if section == 0 {
// Status
return 1
- } else if (section == 1) {
+ } else if section == 1 {
// Interface
return interfaceData.filterFieldsWithValueOrControl(interfaceFields: interfaceFields).count
- } else if ((numberOfPeerSections > 0) && (section < (2 + numberOfPeerSections))) {
+ } else if (numberOfPeerSections > 0) && (section < (2 + numberOfPeerSections)) {
// Peer
let peerData = tunnelViewModel.peersData[section - 2]
return peerData.filterFieldsWithValueOrControl(peerFields: peerFields).count
- } else if (section < (3 + numberOfPeerSections)) {
+ } else if section < (3 + numberOfPeerSections) {
// Activate on demand
return 1
} else {
@@ -122,16 +122,16 @@ extension TunnelDetailTableViewController {
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
let numberOfPeerSections = tunnelViewModel.peersData.count
- if (section == 0) {
+ if section == 0 {
// Status
return "Status"
- } else if (section == 1) {
+ } else if section == 1 {
// Interface
return "Interface"
- } else if ((numberOfPeerSections > 0) && (section < (2 + numberOfPeerSections))) {
+ } else if (numberOfPeerSections > 0) && (section < (2 + numberOfPeerSections)) {
// Peer
return "Peer"
- } else if (section < (3 + numberOfPeerSections)) {
+ } else if section < (3 + numberOfPeerSections) {
// On-Demand Activation
return "On-Demand Activation"
} else {
@@ -147,13 +147,13 @@ extension TunnelDetailTableViewController {
let section = indexPath.section
let row = indexPath.row
- if (section == 0) {
+ if section == 0 {
// Status
- let cell = tableView.dequeueReusableCell(withIdentifier: TunnelDetailTableViewStatusCell.id, for: indexPath) as! TunnelDetailTableViewStatusCell
+ let cell = tableView.dequeueReusableCell(withIdentifier: TunnelDetailTableViewStatusCell.reuseIdentifier, for: indexPath) as! TunnelDetailTableViewStatusCell
cell.tunnel = self.tunnel
cell.onSwitchToggled = { [weak self] isOn in
guard let self = self else { return }
- if (isOn) {
+ if isOn {
self.tunnelsManager.startActivation(of: self.tunnel) { [weak self] error in
if let error = error {
ErrorPresenter.showErrorAlert(error: error, from: self, onPresented: {
@@ -168,33 +168,33 @@ extension TunnelDetailTableViewController {
}
}
return cell
- } else if (section == 1) {
+ } else if section == 1 {
// Interface
let field = interfaceData.filterFieldsWithValueOrControl(interfaceFields: interfaceFields)[row]
- let cell = tableView.dequeueReusableCell(withIdentifier: TunnelDetailTableViewKeyValueCell.id, for: indexPath) as! TunnelDetailTableViewKeyValueCell
+ let cell = tableView.dequeueReusableCell(withIdentifier: TunnelDetailTableViewKeyValueCell.reuseIdentifier, for: indexPath) as! TunnelDetailTableViewKeyValueCell
// Set key and value
cell.key = field.rawValue
cell.value = interfaceData[field]
return cell
- } else if ((numberOfPeerSections > 0) && (section < (2 + numberOfPeerSections))) {
+ } else if (numberOfPeerSections > 0) && (section < (2 + numberOfPeerSections)) {
// Peer
let peerData = tunnelViewModel.peersData[section - 2]
let field = peerData.filterFieldsWithValueOrControl(peerFields: peerFields)[row]
- let cell = tableView.dequeueReusableCell(withIdentifier: TunnelDetailTableViewKeyValueCell.id, for: indexPath) as! TunnelDetailTableViewKeyValueCell
+ let cell = tableView.dequeueReusableCell(withIdentifier: TunnelDetailTableViewKeyValueCell.reuseIdentifier, for: indexPath) as! TunnelDetailTableViewKeyValueCell
// Set key and value
cell.key = field.rawValue
cell.value = peerData[field]
return cell
- } else if (section < (3 + numberOfPeerSections)) {
+ } else if section < (3 + numberOfPeerSections) {
// On-Demand Activation
- let cell = tableView.dequeueReusableCell(withIdentifier: TunnelDetailTableViewActivateOnDemandCell.id, for: indexPath) as! TunnelDetailTableViewActivateOnDemandCell
+ let cell = tableView.dequeueReusableCell(withIdentifier: TunnelDetailTableViewActivateOnDemandCell.reuseIdentifier, for: indexPath) as! TunnelDetailTableViewActivateOnDemandCell
cell.tunnel = self.tunnel
return cell
} else {
assert(section == (3 + numberOfPeerSections))
// Delete configuration
- let cell = tableView.dequeueReusableCell(withIdentifier: TunnelDetailTableViewButtonCell.id, for: indexPath) as! TunnelDetailTableViewButtonCell
+ let cell = tableView.dequeueReusableCell(withIdentifier: TunnelDetailTableViewButtonCell.reuseIdentifier, for: indexPath) as! TunnelDetailTableViewButtonCell
cell.buttonText = "Delete tunnel"
cell.hasDestructiveAction = true
cell.onTapped = { [weak self] in
@@ -202,7 +202,7 @@ extension TunnelDetailTableViewController {
self.showConfirmationAlert(message: "Delete this tunnel?", buttonTitle: "Delete", from: cell) { [weak self] in
guard let tunnelsManager = self?.tunnelsManager, let tunnel = self?.tunnel else { return }
tunnelsManager.remove(tunnel: tunnel) { (error) in
- if (error != nil) {
+ if error != nil {
print("Error removing tunnel: \(String(describing: error))")
return
}
@@ -216,7 +216,7 @@ extension TunnelDetailTableViewController {
}
class TunnelDetailTableViewStatusCell: UITableViewCell {
- static let id: String = "TunnelDetailTableViewStatusCell"
+ static let reuseIdentifier = "TunnelDetailTableViewStatusCell"
var tunnel: TunnelContainer? {
didSet(value) {
@@ -238,14 +238,14 @@ class TunnelDetailTableViewStatusCell: UITableViewCell {
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
statusSwitch = UISwitch()
- super.init(style: .default, reuseIdentifier: TunnelDetailTableViewKeyValueCell.id)
+ super.init(style: .default, reuseIdentifier: TunnelDetailTableViewKeyValueCell.reuseIdentifier)
accessoryView = statusSwitch
statusSwitch.addTarget(self, action: #selector(switchToggled), for: .valueChanged)
}
@objc func switchToggled() {
- if (isOnSwitchToggledHandlerEnabled) {
+ if isOnSwitchToggledHandlerEnabled {
onSwitchToggled?(statusSwitch.isOn)
}
}
@@ -256,7 +256,7 @@ class TunnelDetailTableViewStatusCell: UITableViewCell {
return
}
let text: String
- switch (status) {
+ switch status {
case .inactive:
text = "Inactive"
case .activating:
@@ -297,7 +297,7 @@ class TunnelDetailTableViewStatusCell: UITableViewCell {
}
class TunnelDetailTableViewKeyValueCell: CopyableLabelTableViewCell {
- static let id: String = "TunnelDetailTableViewKeyValueCell"
+ static let reuseIdentifier = "TunnelDetailTableViewKeyValueCell"
var key: String {
get { return keyLabel.text ?? "" }
set(value) { keyLabel.text = value }
@@ -357,9 +357,9 @@ class TunnelDetailTableViewKeyValueCell: CopyableLabelTableViewCell {
func configureForContentSize() {
var constraints: [NSLayoutConstraint] = []
- if (self.traitCollection.preferredContentSizeCategory.isAccessibilityCategory) {
+ if self.traitCollection.preferredContentSizeCategory.isAccessibilityCategory {
// Stack vertically
- if (!isStackedVertically) {
+ if !isStackedVertically {
constraints = [
valueLabel.topAnchor.constraint(equalToSystemSpacingBelow: keyLabel.bottomAnchor, multiplier: 0.5),
valueLabel.leftAnchor.constraint(equalTo: contentView.layoutMarginsGuide.leftAnchor),
@@ -370,7 +370,7 @@ class TunnelDetailTableViewKeyValueCell: CopyableLabelTableViewCell {
}
} else {
// Stack horizontally
- if (!isStackedHorizontally) {
+ if !isStackedHorizontally {
constraints = [
contentView.layoutMarginsGuide.bottomAnchor.constraint(equalToSystemSpacingBelow: keyLabel.bottomAnchor, multiplier: 0.5),
valueLabel.leftAnchor.constraint(equalToSystemSpacingAfter: keyLabel.rightAnchor, multiplier: 1),
@@ -380,7 +380,7 @@ class TunnelDetailTableViewKeyValueCell: CopyableLabelTableViewCell {
isStackedVertically = false
}
}
- if (!constraints.isEmpty) {
+ if !constraints.isEmpty {
NSLayoutConstraint.deactivate(self.contentSizeBasedConstraints)
NSLayoutConstraint.activate(constraints)
self.contentSizeBasedConstraints = constraints
@@ -400,7 +400,7 @@ class TunnelDetailTableViewKeyValueCell: CopyableLabelTableViewCell {
}
class TunnelDetailTableViewButtonCell: UITableViewCell {
- static let id: String = "TunnelDetailTableViewButtonCell"
+ static let reuseIdentifier = "TunnelDetailTableViewButtonCell"
var buttonText: String {
get { return button.title(for: .normal) ?? "" }
set(value) { button.setTitle(value, for: .normal) }
@@ -447,7 +447,7 @@ class TunnelDetailTableViewButtonCell: UITableViewCell {
}
class TunnelDetailTableViewActivateOnDemandCell: UITableViewCell {
- static let id: String = "TunnelDetailTableViewActivateOnDemandCell"
+ static let reuseIdentifier = "TunnelDetailTableViewActivateOnDemandCell"
var tunnel: TunnelContainer? {
didSet(value) {
diff --git a/WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift
index abe573a..330a3cc 100644
--- a/WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift
@@ -82,7 +82,7 @@ class TunnelEditTableViewController: UITableViewController {
@objc func saveTapped() {
self.tableView.endEditing(false)
let tunnelSaveResult = tunnelViewModel.save()
- switch (tunnelSaveResult) {
+ switch tunnelSaveResult {
case .error(let errorMessage):
let erroringConfiguration = (tunnelViewModel.interfaceData.validatedConfiguration == nil) ? "Interface" : "Peer"
ErrorPresenter.showErrorAlert(title: "Invalid \(erroringConfiguration)", message: errorMessage, from: self)
@@ -130,21 +130,21 @@ extension TunnelEditTableViewController {
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- if (section < interfaceSectionCount) {
+ if section < interfaceSectionCount {
// Interface
return interfaceFieldsBySection[section].count
- } else if ((peerSectionCount > 0) && (section < (interfaceSectionCount + peerSectionCount))) {
+ } else if (peerSectionCount > 0) && (section < (interfaceSectionCount + peerSectionCount)) {
// Peer
let peerIndex = (section - interfaceSectionCount)
let peerData = tunnelViewModel.peersData[peerIndex]
let peerFieldsToShow = peerData.shouldAllowExcludePrivateIPsControl ? peerFields : peerFields.filter { $0 != .excludePrivateIPs }
return peerFieldsToShow.count
- } else if (section < (interfaceSectionCount + peerSectionCount + 1)) {
+ } else if section < (interfaceSectionCount + peerSectionCount + 1) {
// Add peer
return 1
} else {
// On-Demand Rules
- if (activateOnDemandSetting.isActivateOnDemandEnabled) {
+ if activateOnDemandSetting.isActivateOnDemandEnabled {
return 4
} else {
return 1
@@ -153,13 +153,13 @@ extension TunnelEditTableViewController {
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
- if (section < interfaceSectionCount) {
+ if section < interfaceSectionCount {
// Interface
return (section == 0) ? "Interface" : nil
- } else if ((peerSectionCount > 0) && (section < (interfaceSectionCount + peerSectionCount))) {
+ } else if (peerSectionCount > 0) && (section < (interfaceSectionCount + peerSectionCount)) {
// Peer
return "Peer"
- } else if (section == (interfaceSectionCount + peerSectionCount)) {
+ } else if section == (interfaceSectionCount + peerSectionCount) {
// Add peer
return nil
} else {
@@ -169,11 +169,11 @@ extension TunnelEditTableViewController {
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- if (indexPath.section < interfaceSectionCount) {
+ if indexPath.section < interfaceSectionCount {
return interfaceFieldCell(for: tableView, at: indexPath)
- } else if ((peerSectionCount > 0) && (indexPath.section < (interfaceSectionCount + peerSectionCount))) {
+ } else if (peerSectionCount > 0) && (indexPath.section < (interfaceSectionCount + peerSectionCount)) {
return peerCell(for: tableView, at: indexPath)
- } else if (indexPath.section == (interfaceSectionCount + peerSectionCount)) {
+ } else if indexPath.section == (interfaceSectionCount + peerSectionCount) {
return addPeerCell(for: tableView, at: indexPath)
} else {
return onDemandCell(for: tableView, at: indexPath)
@@ -183,7 +183,7 @@ extension TunnelEditTableViewController {
private func interfaceFieldCell(for tableView: UITableView, at indexPath: IndexPath) -> UITableViewCell {
let interfaceData = tunnelViewModel.interfaceData
let field = interfaceFieldsBySection[indexPath.section][indexPath.row]
- if (field == .generateKeyPair) {
+ if field == .generateKeyPair {
let cell = tableView.dequeueReusableCell(withIdentifier: TunnelEditTableViewButtonCell.reuseIdentifier, for: indexPath) as! TunnelEditTableViewButtonCell
cell.buttonText = field.rawValue
cell.onTapped = { [weak self, weak interfaceData] in
@@ -550,9 +550,9 @@ class TunnelEditTableViewKeyValueCell: UITableViewCell {
func configureForContentSize() {
var constraints: [NSLayoutConstraint] = []
- if (self.traitCollection.preferredContentSizeCategory.isAccessibilityCategory) {
+ if self.traitCollection.preferredContentSizeCategory.isAccessibilityCategory {
// Stack vertically
- if (!isStackedVertically) {
+ if !isStackedVertically {
constraints = [
valueTextField.topAnchor.constraint(equalToSystemSpacingBelow: keyLabel.bottomAnchor, multiplier: 0.5),
valueTextField.leftAnchor.constraint(equalTo: contentView.layoutMarginsGuide.leftAnchor),
@@ -563,7 +563,7 @@ class TunnelEditTableViewKeyValueCell: UITableViewCell {
}
} else {
// Stack horizontally
- if (!isStackedHorizontally) {
+ if !isStackedHorizontally {
constraints = [
contentView.layoutMarginsGuide.bottomAnchor.constraint(equalToSystemSpacingBelow: keyLabel.bottomAnchor, multiplier: 0.5),
valueTextField.leftAnchor.constraint(equalToSystemSpacingAfter: keyLabel.rightAnchor, multiplier: 1),
@@ -573,7 +573,7 @@ class TunnelEditTableViewKeyValueCell: UITableViewCell {
isStackedVertically = false
}
}
- if (!constraints.isEmpty) {
+ if !constraints.isEmpty {
NSLayoutConstraint.deactivate(self.contentSizeBasedConstraints)
NSLayoutConstraint.activate(constraints)
self.contentSizeBasedConstraints = constraints
@@ -604,7 +604,7 @@ extension TunnelEditTableViewKeyValueCell: UITextFieldDelegate {
}
func textFieldDidEndEditing(_ textField: UITextField) {
let isModified = (textField.text ?? "" != textFieldValueOnBeginEditing)
- guard (isModified) else { return }
+ guard isModified else { return }
if let onValueChanged = onValueChanged {
onValueChanged(textField.text ?? "")
}
diff --git a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift
index 07fbee4..bd5f972 100644
--- a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift
@@ -43,7 +43,7 @@ class TunnelsListTableViewController: UIViewController {
}
func setTunnelsManager(tunnelsManager: TunnelsManager) {
- if (self.tunnelsManager != nil) {
+ if self.tunnelsManager != nil {
// If a tunnels manager is already set, do nothing
return
}
@@ -54,7 +54,7 @@ class TunnelsListTableViewController: UIViewController {
tableView.estimatedRowHeight = 60
tableView.rowHeight = UITableView.automaticDimension
tableView.separatorStyle = .none
- tableView.register(TunnelsListTableViewCell.self, forCellReuseIdentifier: TunnelsListTableViewCell.id)
+ tableView.register(TunnelsListTableViewCell.self, forCellReuseIdentifier: TunnelsListTableViewCell.reuseIdentifier)
self.view.addSubview(tableView)
tableView.translatesAutoresizingMaskIntoConstraints = false
@@ -103,7 +103,7 @@ class TunnelsListTableViewController: UIViewController {
}
@objc func addButtonTapped(sender: AnyObject) {
- if (self.tunnelsManager == nil) { return } // Do nothing until we've loaded the tunnels
+ if self.tunnelsManager == nil { return } // Do nothing until we've loaded the tunnels
let alert = UIAlertController(title: "", message: "Add a new WireGuard tunnel", preferredStyle: .actionSheet)
let importFileAction = UIAlertAction(title: "Create from file or archive", style: .default) { [weak self] (_) in
self?.presentViewControllerForFileImport()
@@ -136,7 +136,7 @@ class TunnelsListTableViewController: UIViewController {
}
@objc func settingsButtonTapped(sender: UIBarButtonItem!) {
- if (self.tunnelsManager == nil) { return } // Do nothing until we've loaded the tunnels
+ if self.tunnelsManager == nil { return } // Do nothing until we've loaded the tunnels
let settingsVC = SettingsTableViewController(tunnelsManager: tunnelsManager)
let settingsNC = UINavigationController(rootViewController: settingsVC)
settingsNC.modalPresentationStyle = .formSheet
@@ -167,7 +167,7 @@ class TunnelsListTableViewController: UIViewController {
func importFromFile(url: URL, completionHandler: (() -> Void)?) {
guard let tunnelsManager = tunnelsManager else { return }
- if (url.pathExtension == "zip") {
+ if url.pathExtension == "zip" {
ZipImporter.importConfigFiles(from: url) { [weak self] result in
if let error = result.error {
ErrorPresenter.showErrorAlert(error: error, from: self)
@@ -241,13 +241,13 @@ extension TunnelsListTableViewController: UITableViewDataSource {
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: TunnelsListTableViewCell.id, for: indexPath) as! TunnelsListTableViewCell
+ let cell = tableView.dequeueReusableCell(withIdentifier: TunnelsListTableViewCell.reuseIdentifier, for: indexPath) as! TunnelsListTableViewCell
if let tunnelsManager = tunnelsManager {
let tunnel = tunnelsManager.tunnel(at: indexPath.row)
cell.tunnel = tunnel
cell.onSwitchToggled = { [weak self] isOn in
guard let self = self, let tunnelsManager = self.tunnelsManager else { return }
- if (isOn) {
+ if isOn {
tunnelsManager.startActivation(of: tunnel) { [weak self] error in
if let error = error {
ErrorPresenter.showErrorAlert(error: error, from: self, onPresented: {
@@ -285,7 +285,7 @@ extension TunnelsListTableViewController: UITableViewDelegate {
guard let tunnelsManager = self?.tunnelsManager else { return }
let tunnel = tunnelsManager.tunnel(at: indexPath.row)
tunnelsManager.remove(tunnel: tunnel, completionHandler: { (error) in
- if (error != nil) {
+ if error != nil {
ErrorPresenter.showErrorAlert(error: error!, from: self)
completionHandler(false)
} else {
@@ -309,7 +309,7 @@ extension TunnelsListTableViewController: TunnelsManagerListDelegate {
tableView?.reloadRows(at: [IndexPath(row: index, section: 0)], with: .automatic)
}
- func tunnelMoved(at oldIndex: Int, to newIndex: Int) {
+ func tunnelMoved(from oldIndex: Int, to newIndex: Int) {
tableView?.moveRow(at: IndexPath(row: oldIndex, section: 0), to: IndexPath(row: newIndex, section: 0))
}
@@ -320,7 +320,7 @@ extension TunnelsListTableViewController: TunnelsManagerListDelegate {
}
class TunnelsListTableViewCell: UITableViewCell {
- static let id: String = "TunnelsListTableViewCell"
+ static let reuseIdentifier = "TunnelsListTableViewCell"
var tunnel: TunnelContainer? {
didSet(value) {
// Bind to the tunnel's name
@@ -396,7 +396,7 @@ class TunnelsListTableViewCell: UITableViewCell {
guard let statusSwitch = statusSwitch, let busyIndicator = busyIndicator else { return }
statusSwitch.isOn = !(status == .deactivating || status == .inactive)
statusSwitch.isUserInteractionEnabled = (status == .inactive || status == .active)
- if (status == .inactive || status == .active) {
+ if status == .inactive || status == .active {
busyIndicator.stopAnimating()
} else {
busyIndicator.startAnimating()