Skip to content

Commit

Permalink
Swift 5 migration (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
getaaron authored and bcylin committed May 28, 2019
1 parent 0045694 commit f0f5fd8
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Example-iOS/ViewControllers/ExampleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ internal final class ExampleViewController: QuickTableViewController {
private func showDebuggingText(_ text: String) {
print(text)
debugging.rows = [NavigationRow(text: text, detailText: .none)]
if let section = tableContents.index(where: { $0 === debugging }) {
if let section = tableContents.firstIndex(where: { $0 === debugging }) {
tableView.reloadSections([section], with: .none)
}
}
Expand Down
40 changes: 28 additions & 12 deletions QuickTableViewController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -755,52 +755,54 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1000;
LastUpgradeCheck = 0930;
LastUpgradeCheck = 1020;
ORGANIZATIONNAME = bcylin;
TargetAttributes = {
136DD2FC216A367B00F554F0 = {
CreatedOnToolsVersion = 10.0;
LastSwiftMigration = 1020;
ProvisioningStyle = Manual;
TestTargetID = B54A24522088D44A00EEBA26;
};
B51F21A11F417037009BC2C9 = {
CreatedOnToolsVersion = 8.3.3;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
ProvisioningStyle = Manual;
};
B51F21BF1F41E600009BC2C9 = {
CreatedOnToolsVersion = 8.3.3;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
ProvisioningStyle = Manual;
TestTargetID = B51F21A11F417037009BC2C9;
};
B5334F121B8CC5BD00C64A6D = {
CreatedOnToolsVersion = 6.4;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
};
B5334F1D1B8CC5BD00C64A6D = {
CreatedOnToolsVersion = 6.4;
LastSwiftMigration = 0930;
LastSwiftMigration = 1020;
};
B54A24252088816D00EEBA26 = {
CreatedOnToolsVersion = 9.3;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
};
B54A242D2088816E00EEBA26 = {
CreatedOnToolsVersion = 9.3;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
};
B54A24522088D44A00EEBA26 = {
CreatedOnToolsVersion = 9.3;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
};
};
};
buildConfigurationList = B5334F0D1B8CC5BD00C64A6D /* Build configuration list for PBXProject "QuickTableViewController" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Expand Down Expand Up @@ -1241,7 +1243,7 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = appletvos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
TEST_TARGET_NAME = "Example-tvOS";
TVOS_DEPLOYMENT_TARGET = 12.0;
Expand All @@ -1268,7 +1270,7 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = appletvos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
TEST_TARGET_NAME = "Example-tvOS";
TVOS_DEPLOYMENT_TARGET = 12.0;
Expand All @@ -1292,6 +1294,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -1311,6 +1314,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand All @@ -1333,6 +1337,7 @@
PROVISIONING_PROFILE = "";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 5.0;
TEST_TARGET_NAME = "Example-iOS";
};
name = Debug;
Expand All @@ -1355,6 +1360,7 @@
PROVISIONING_PROFILE = "";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
TEST_TARGET_NAME = "Example-iOS";
};
name = Release;
Expand All @@ -1363,6 +1369,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_CODE_COVERAGE = YES;
Expand Down Expand Up @@ -1427,6 +1434,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_CODE_COVERAGE = YES;
Expand Down Expand Up @@ -1495,6 +1503,7 @@
PRODUCT_NAME = QuickTableViewController;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -1514,6 +1523,7 @@
PRODUCT_NAME = QuickTableViewController;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand All @@ -1534,7 +1544,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = io.github.bcylin.QuickTableViewControllerTests;
PRODUCT_NAME = QuickTableViewControllerTests;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -1552,7 +1562,7 @@
PRODUCT_BUNDLE_IDENTIFIER = io.github.bcylin.QuickTableViewControllerTests;
PRODUCT_NAME = QuickTableViewControllerTests;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down Expand Up @@ -1581,6 +1591,7 @@
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand Down Expand Up @@ -1610,6 +1621,7 @@
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand All @@ -1635,6 +1647,7 @@
PRODUCT_NAME = QuickTableViewControllerTests;
SDKROOT = appletvos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 11.3;
};
Expand All @@ -1659,6 +1672,7 @@
PRODUCT_NAME = QuickTableViewControllerTests;
SDKROOT = appletvos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 11.3;
};
Expand All @@ -1685,6 +1699,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand All @@ -1710,6 +1725,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1010"
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1010"
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1010"
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1010"
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
12 changes: 6 additions & 6 deletions Source/Model/Deprecated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ import Foundation
public extension Row {

@available(*, deprecated, message: "Use `text` instead.")
public var title: String {
var title: String {
return text
}

@available(*, deprecated, message: "Use `detailText` instead.")
public var subtitle: Subtitle? {
var subtitle: Subtitle? {
return detailText?.subtitle
}

Expand All @@ -45,7 +45,7 @@ public extension Row {
public extension NavigationRow {

@available(*, deprecated, message: "Use `init(text:detailText:icon:customization:action:)` instead.")
public convenience init(
convenience init(
title: String,
subtitle: Subtitle,
icon: Icon? = nil,
Expand All @@ -68,7 +68,7 @@ public extension NavigationRow {
public extension OptionRow {

@available(*, deprecated, message: "Use `init(text:detailText:isSelected:icon:customization:action:)` instead.")
public convenience init(
convenience init(
title: String,
isSelected: Bool,
icon: Icon? = nil,
Expand All @@ -92,7 +92,7 @@ public extension OptionRow {
public extension SwitchRow {

@available(*, deprecated, message: "Use `init(text:detailText:switchValue:icon:customization:action:)` instead.")
public convenience init(
convenience init(
title: String,
switchValue: Bool,
icon: Icon? = nil,
Expand All @@ -116,7 +116,7 @@ public extension SwitchRow {
public extension TapActionRow {

@available(*, deprecated, message: "Use `init(text:customization:action:)` instead.")
public convenience init(
convenience init(
title: String,
customization: ((UITableViewCell, Row & RowStyle) -> Void)? = nil,
action: ((Row) -> Void)?
Expand Down
4 changes: 2 additions & 2 deletions Source/Model/RadioSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ open class RadioSection: Section {

/// Returns the selected index, or nil when nothing is selected.
open var indexOfSelectedOption: Int? {
return options.index { $0.isSelected }
return options.firstIndex { $0.isSelected }
}

/// Returns the selected option row, or nil when nothing is selected.
Expand Down Expand Up @@ -97,7 +97,7 @@ open class RadioSection: Section {

if option.isSelected {
// Deselect the selected option.
return options.index(where: { $0 === option }).map { [$0] } ?? []
return options.firstIndex(where: { $0 === option }).map { [$0] } ?? []
}

var toggledIndexes: IndexSet = []
Expand Down
2 changes: 1 addition & 1 deletion Source/Model/Subtitle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public enum Subtitle: Equatable {
internal extension DetailText {

@available(*, deprecated, message: "The conversion between DetailText and Subtitle.")
internal var subtitle: Subtitle {
var subtitle: Subtitle {
switch self {
case .none: return .none
case let .subtitle(text): return .belowTitle(text)
Expand Down
6 changes: 3 additions & 3 deletions Source/Protocol/Reusable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal protocol Reusable {

internal extension Reusable {

internal static var reuseIdentifier: String {
static var reuseIdentifier: String {
let type = String(describing: self)
return type.matches(of: String.typeDescriptionPattern).last ?? type
}
Expand All @@ -46,12 +46,12 @@ internal extension Reusable {

internal extension String {

internal static var typeDescriptionPattern: String {
static var typeDescriptionPattern: String {
// For the types in the format of "(CustomCell in _B5334F301B8CC6AA00C64A6D)"
return "^\\(([\\w\\d]+)\\sin\\s_[0-9A-F]+\\)$"
}

internal func matches(of pattern: String) -> [String] {
func matches(of pattern: String) -> [String] {
let regex = try? NSRegularExpression(pattern: pattern, options: .caseInsensitive)
#if swift(>=3.2)
let fullText = NSRange(location: 0, length: count)
Expand Down
9 changes: 5 additions & 4 deletions Source/Rows/NavigationRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,11 @@ private extension UITableViewCell.CellStyle {

var stringValue: String {
switch self {
case .default: return ".default"
case .subtitle: return ".subtitle"
case .value1: return ".value1"
case .value2: return ".value2"
case .default: return ".default"
case .subtitle: return ".subtitle"
case .value1: return ".value1"
case .value2: return ".value2"
@unknown default: return ".default"
}
}

Expand Down

0 comments on commit f0f5fd8

Please sign in to comment.