Migrate to Swift 5

Last time was probably incomplete.
This commit is contained in:
Davide De Rosa 2019-04-11 16:51:03 +02:00
parent 60259a2fb9
commit 4add7a695c
7 changed files with 21 additions and 15 deletions

View File

@ -47,7 +47,7 @@ class OptionViewController<T: Hashable>: UIViewController, UITableViewDataSource
tableView.dataSource = self
tableView.delegate = self
if let selectedOption = selectedOption, let row = options.index(of: selectedOption) {
if let selectedOption = selectedOption, let row = options.firstIndex(of: selectedOption) {
tableView.reloadData()
tableView.scrollToRowAsync(at: IndexPath(row: row, section: 0))
}

View File

@ -181,7 +181,7 @@ extension EndpointViewController: UITableViewDataSource, UITableViewDelegate {
}
private var selectedIndexPath: IndexPath? {
guard let i = endpointAddresses.index(where: { $0 == currentAddress }) else {
guard let i = endpointAddresses.firstIndex(where: { $0 == currentAddress }) else {
return nil
}
return IndexPath(row: i, section: 0)

View File

@ -119,10 +119,10 @@ extension ProviderPoolViewController: UITableViewDataSource, UITableViewDelegate
private var selectedIndexPath: IndexPath? {
for (i, model) in models.enumerated() {
for entries in model.poolsByGroup.enumerated() {
guard let _ = entries.element.value.index(where: { $0.id == currentPool?.id }) else {
guard let _ = entries.element.value.firstIndex(where: { $0.id == currentPool?.id }) else {
continue
}
guard let row = model.sortedGroups.index(of: entries.element.key) else {
guard let row = model.sortedGroups.firstIndex(of: entries.element.key) else {
continue
}
return IndexPath(row: row, section: i)

View File

@ -78,7 +78,7 @@ extension ProviderPresetViewController: UITableViewDataSource, UITableViewDelega
}
private var selectedIndexPath: IndexPath? {
guard let i = presets.index(where: { $0.id == currentPresetId }) else {
guard let i = presets.firstIndex(where: { $0.id == currentPresetId }) else {
return nil
}
return IndexPath(row: 0, section: i)

View File

@ -69,7 +69,7 @@ class TableModel<S: Hashable, R: Equatable> {
}
func index(ofSection sectionObject: S) -> Int {
guard let sectionIndex = sections.index(of: sectionObject) else {
guard let sectionIndex = sections.firstIndex(of: sectionObject) else {
fatalError("Missing section: \(sectionObject)")
}
return sectionIndex
@ -92,10 +92,10 @@ class TableModel<S: Hashable, R: Equatable> {
}
func indexPath(row rowObject: R, section sectionObject: S) -> IndexPath? {
guard let sectionIndex = sections.index(of: sectionObject) else {
guard let sectionIndex = sections.firstIndex(of: sectionObject) else {
return nil
}
guard let row = rowsBySection[sectionObject]?.index(of: rowObject) else {
guard let row = rowsBySection[sectionObject]?.firstIndex(of: rowObject) else {
return nil
}
return IndexPath(row: row, section: sectionIndex)

View File

@ -743,13 +743,15 @@
TargetAttributes = {
0E31529A223F9EF400F61841 = {
CreatedOnToolsVersion = 10.1;
LastSwiftMigration = 1020;
};
0E3152A2223F9EF500F61841 = {
CreatedOnToolsVersion = 10.1;
LastSwiftMigration = 1020;
};
0E57F63720C83FC5008323CF = {
CreatedOnToolsVersion = 9.4;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
SystemCapabilities = {
com.apple.AccessWiFi = {
enabled = 1;
@ -767,7 +769,7 @@
};
0EDE8DBE20C86910004C739C = {
CreatedOnToolsVersion = 10.0;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
SystemCapabilities = {
com.apple.ApplicationGroups.iOS = {
enabled = 1;
@ -1220,7 +1222,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.algoritmico.ios.Passepartout-Core";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
@ -1251,7 +1253,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.algoritmico.ios.Passepartout-Core";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
@ -1274,7 +1276,7 @@
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.algoritmico.ios.Passepartout-CoreTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
@ -1294,7 +1296,7 @@
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.algoritmico.ios.Passepartout-CoreTests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
@ -1444,6 +1446,7 @@
PRODUCT_NAME = Passepartout;
PROVISIONING_PROFILE_SPECIFIER = "match Development com.algoritmico.ios.Passepartout";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
@ -1466,6 +1469,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.algoritmico.ios.Passepartout;
PRODUCT_NAME = Passepartout;
PROVISIONING_PROFILE_SPECIFIER = "match Development com.algoritmico.ios.Passepartout";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
@ -1489,6 +1493,7 @@
PRODUCT_NAME = "Passepartout-Tunnel";
PROVISIONING_PROFILE_SPECIFIER = "match Development com.algoritmico.ios.Passepartout.Tunnel";
SKIP_INSTALL = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
@ -1511,6 +1516,7 @@
PRODUCT_NAME = "Passepartout-Tunnel";
PROVISIONING_PROFILE_SPECIFIER = "match Development com.algoritmico.ios.Passepartout.Tunnel";
SKIP_INSTALL = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;

View File

@ -79,7 +79,7 @@ public struct InfrastructurePreset: Codable {
public let configuration: TunnelKitProvider.Configuration
public func hasProtocol(_ proto: EndpointProtocol) -> Bool {
return configuration.sessionConfiguration.endpointProtocols?.index(of: proto) != nil
return configuration.sessionConfiguration.endpointProtocols?.firstIndex(of: proto) != nil
}
// MARK: Codable