From a3022eb35680309e71778b47db761e61e426ce80 Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 25 Jun 2020 21:59:21 +0100 Subject: [PATCH 1/3] Fix an issue where the same identifier is used for different cell types --- Source/Rows/NavigationRow.swift | 2 +- Source/Rows/OptionRow.swift | 6 ++++-- Source/Rows/SwitchRow.swift | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Source/Rows/NavigationRow.swift b/Source/Rows/NavigationRow.swift index bd515dd5..3e7d8965 100644 --- a/Source/Rows/NavigationRow.swift +++ b/Source/Rows/NavigationRow.swift @@ -143,7 +143,7 @@ open class NavigationRow: NavigationRowCompatible, Equatable } -private extension UITableViewCell.CellStyle { +internal extension UITableViewCell.CellStyle { var stringValue: String { switch self { diff --git a/Source/Rows/OptionRow.swift b/Source/Rows/OptionRow.swift index 4bb41810..a9f712ef 100644 --- a/Source/Rows/OptionRow.swift +++ b/Source/Rows/OptionRow.swift @@ -79,8 +79,10 @@ open class OptionRow: OptionRowCompatible, Equatable { /// The type of the table view cell to display the row. public let cellType: UITableViewCell.Type = T.self - /// The reuse identifier of the table view cell to display the row. The default value is **UITableViewCell**. - public let cellReuseIdentifier: String = T.reuseIdentifier + /// Returns the reuse identifier of the table view cell to display the row. + public var cellReuseIdentifier: String { + return T.reuseIdentifier + (detailText?.style.stringValue ?? "") + } /// Returns the table view cell style for the specified detail text. public var cellStyle: UITableViewCell.CellStyle { diff --git a/Source/Rows/SwitchRow.swift b/Source/Rows/SwitchRow.swift index a0a401bf..681c3ec4 100644 --- a/Source/Rows/SwitchRow.swift +++ b/Source/Rows/SwitchRow.swift @@ -79,8 +79,10 @@ open class SwitchRow: SwitchRowCompatible, Equatable { /// The type of the table view cell to display the row. public let cellType: UITableViewCell.Type = T.self - /// The reuse identifier of the table view cell to display the row. The default value is **SwitchCell**. - public let cellReuseIdentifier: String = T.reuseIdentifier + /// Returns the reuse identifier of the table view cell to display the row. + public var cellReuseIdentifier: String { + return T.reuseIdentifier + (detailText?.style.stringValue ?? "") + } /// Returns the table view cell style for the specified detail text. public var cellStyle: UITableViewCell.CellStyle { From 65ff543c77ab8d1abf40f7b651b3bea3b337245c Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 25 Jun 2020 22:05:54 +0100 Subject: [PATCH 2/3] Add cell style and reuse identifier tests --- Tests/CustomTypes.swift | 1 + Tests/Row/NavigationRowTests.swift | 26 ++++++++++++++++- Tests/Row/OptionRowTests.swift | 46 +++++++++++++++++++++++++++++- Tests/Row/SwitchRowTests.swift | 46 +++++++++++++++++++++++++++++- Tests/Row/TapActionRowTests.swift | 9 ++++++ 5 files changed, 125 insertions(+), 3 deletions(-) diff --git a/Tests/CustomTypes.swift b/Tests/CustomTypes.swift index 11c13e88..7e8f7863 100644 --- a/Tests/CustomTypes.swift +++ b/Tests/CustomTypes.swift @@ -30,6 +30,7 @@ import UIKit internal final class CustomCell: UITableViewCell {} internal final class CustomSwitchCell: SwitchCell {} internal final class CustomTapActionCell: TapActionCell {} +internal final class CustomOptionCell: UITableViewCell {} internal final class CustomNavigationRow: NavigationRow {} internal final class CustomSwitchRow: SwitchRow {} diff --git a/Tests/Row/NavigationRowTests.swift b/Tests/Row/NavigationRowTests.swift index 87307d81..1d12da47 100644 --- a/Tests/Row/NavigationRowTests.swift +++ b/Tests/Row/NavigationRowTests.swift @@ -100,7 +100,7 @@ internal final class NavigationRowTests: XCTestCase { } #endif - func testCellReuseIdentifier() { + func testCellStyleWithReuseIdentifier() { // When let a = NavigationRow(text: "", detailText: .none) let b = NavigationRow(text: "", detailText: .subtitle("")) @@ -108,12 +108,36 @@ internal final class NavigationRowTests: XCTestCase { let d = NavigationRow(text: "", detailText: .value2("")) // Then + XCTAssertEqual(a.cellStyle, .default) + XCTAssertEqual(b.cellStyle, .subtitle) + XCTAssertEqual(c.cellStyle, .value1) + XCTAssertEqual(d.cellStyle, .value2) + XCTAssertEqual(a.cellReuseIdentifier, "UITableViewCell.default") XCTAssertEqual(b.cellReuseIdentifier, "UITableViewCell.subtitle") XCTAssertEqual(c.cellReuseIdentifier, "UITableViewCell.value1") XCTAssertEqual(d.cellReuseIdentifier, "UITableViewCell.value2") } + func testCellStyleWithReuseIdentifier_customCellType() { + // When + let a = NavigationRow(text: "", detailText: .none) + let b = NavigationRow(text: "", detailText: .subtitle("")) + let c = NavigationRow(text: "", detailText: .value1("")) + let d = NavigationRow(text: "", detailText: .value2("")) + + // Then + XCTAssertEqual(a.cellStyle, .default) + XCTAssertEqual(b.cellStyle, .subtitle) + XCTAssertEqual(c.cellStyle, .value1) + XCTAssertEqual(d.cellStyle, .value2) + + XCTAssertEqual(a.cellReuseIdentifier, "CustomCell.default") + XCTAssertEqual(b.cellReuseIdentifier, "CustomCell.subtitle") + XCTAssertEqual(c.cellReuseIdentifier, "CustomCell.value1") + XCTAssertEqual(d.cellReuseIdentifier, "CustomCell.value2") + } + #if os(iOS) func testAccessoryType_iOS() { // When diff --git a/Tests/Row/OptionRowTests.swift b/Tests/Row/OptionRowTests.swift index 7779d1dd..15a292b7 100644 --- a/Tests/Row/OptionRowTests.swift +++ b/Tests/Row/OptionRowTests.swift @@ -46,7 +46,7 @@ internal final class OptionRowTests: XCTestCase { XCTAssertEqual(row.isSelected, true) // With RowStyle - XCTAssertEqual(row.cellReuseIdentifier, "UITableViewCell") + XCTAssertEqual(row.cellReuseIdentifier, "UITableViewCell.subtitle") XCTAssertEqual(row.cellStyle, .subtitle) XCTAssertEqual(row.icon, icon) XCTAssertEqual(row.accessoryType, .checkmark) @@ -60,6 +60,50 @@ internal final class OptionRowTests: XCTestCase { XCTAssertEqual(actionInvoked, true) } + func testCellStyleWithReuseIdentifier() { + // When + let a = OptionRow(text: "", detailText: nil, isSelected: true, action: { _ in }) + let b = OptionRow(text: "", detailText: DetailText.none, isSelected: true, action: { _ in }) + let c = OptionRow(text: "", detailText: .subtitle(""), isSelected: true, action: { _ in }) + let d = OptionRow(text: "", detailText: .value1(""), isSelected: true, action: { _ in }) + let e = OptionRow(text: "", detailText: .value2(""), isSelected: true, action: { _ in }) + + // Then + XCTAssertEqual(a.cellStyle, .default) + XCTAssertEqual(b.cellStyle, .default) + XCTAssertEqual(c.cellStyle, .subtitle) + XCTAssertEqual(d.cellStyle, .value1) + XCTAssertEqual(e.cellStyle, .value2) + + XCTAssertEqual(a.cellReuseIdentifier, "UITableViewCell") + XCTAssertEqual(b.cellReuseIdentifier, "UITableViewCell.default") + XCTAssertEqual(c.cellReuseIdentifier, "UITableViewCell.subtitle") + XCTAssertEqual(d.cellReuseIdentifier, "UITableViewCell.value1") + XCTAssertEqual(e.cellReuseIdentifier, "UITableViewCell.value2") + } + + func testCellStyleWithReuseIdentifier_customCellType() { + // When + let a = OptionRow(text: "", detailText: nil, isSelected: true, action: { _ in }) + let b = OptionRow(text: "", detailText: DetailText.none, isSelected: true, action: { _ in }) + let c = OptionRow(text: "", detailText: .subtitle(""), isSelected: true, action: { _ in }) + let d = OptionRow(text: "", detailText: .value1(""), isSelected: true, action: { _ in }) + let e = OptionRow(text: "", detailText: .value2(""), isSelected: true, action: { _ in }) + + // Then + XCTAssertEqual(a.cellStyle, .default) + XCTAssertEqual(b.cellStyle, .default) + XCTAssertEqual(c.cellStyle, .subtitle) + XCTAssertEqual(d.cellStyle, .value1) + XCTAssertEqual(e.cellStyle, .value2) + + XCTAssertEqual(a.cellReuseIdentifier, "CustomOptionCell") + XCTAssertEqual(b.cellReuseIdentifier, "CustomOptionCell.default") + XCTAssertEqual(c.cellReuseIdentifier, "CustomOptionCell.subtitle") + XCTAssertEqual(d.cellReuseIdentifier, "CustomOptionCell.value1") + XCTAssertEqual(e.cellReuseIdentifier, "CustomOptionCell.value2") + } + // MARK: - Equatable func testEquatable_withIdenticalParameters() { diff --git a/Tests/Row/SwitchRowTests.swift b/Tests/Row/SwitchRowTests.swift index 3b94cab7..8c9063e4 100644 --- a/Tests/Row/SwitchRowTests.swift +++ b/Tests/Row/SwitchRowTests.swift @@ -46,7 +46,7 @@ internal final class SwitchRowTests: XCTestCase { XCTAssertEqual(row.switchValue, true) // With RowStyle - XCTAssertEqual(row.cellReuseIdentifier, "SwitchCell") + XCTAssertEqual(row.cellReuseIdentifier, "SwitchCell.subtitle") XCTAssertEqual(row.cellStyle, .subtitle) XCTAssertEqual(row.icon, icon) XCTAssertNil(row.customize) @@ -66,6 +66,50 @@ internal final class SwitchRowTests: XCTestCase { XCTAssertEqual(actionInvoked, true) } + func testCellStyleWithReuseIdentifier() { + // When + let a = SwitchRow(text: "", detailText: nil, switchValue: true, action: { _ in }) + let b = SwitchRow(text: "", detailText: DetailText.none, switchValue: true, action: { _ in }) + let c = SwitchRow(text: "", detailText: .subtitle(""), switchValue: true, action: { _ in }) + let d = SwitchRow(text: "", detailText: .value1(""), switchValue: true, action: { _ in }) + let e = SwitchRow(text: "", detailText: .value2(""), switchValue: true, action: { _ in }) + + // Then + XCTAssertEqual(a.cellStyle, .default) + XCTAssertEqual(b.cellStyle, .default) + XCTAssertEqual(c.cellStyle, .subtitle) + XCTAssertEqual(d.cellStyle, .value1) + XCTAssertEqual(e.cellStyle, .value2) + + XCTAssertEqual(a.cellReuseIdentifier, "SwitchCell") + XCTAssertEqual(b.cellReuseIdentifier, "SwitchCell.default") + XCTAssertEqual(c.cellReuseIdentifier, "SwitchCell.subtitle") + XCTAssertEqual(d.cellReuseIdentifier, "SwitchCell.value1") + XCTAssertEqual(e.cellReuseIdentifier, "SwitchCell.value2") + } + + func testCellStyleWithReuseIdentifier_customCellType() { + // When + let a = SwitchRow(text: "", detailText: nil, switchValue: true, action: { _ in }) + let b = SwitchRow(text: "", detailText: DetailText.none, switchValue: true, action: { _ in }) + let c = SwitchRow(text: "", detailText: .subtitle(""), switchValue: true, action: { _ in }) + let d = SwitchRow(text: "", detailText: .value1(""), switchValue: true, action: { _ in }) + let e = SwitchRow(text: "", detailText: .value2(""), switchValue: true, action: { _ in }) + + // Then + XCTAssertEqual(a.cellStyle, .default) + XCTAssertEqual(b.cellStyle, .default) + XCTAssertEqual(c.cellStyle, .subtitle) + XCTAssertEqual(d.cellStyle, .value1) + XCTAssertEqual(e.cellStyle, .value2) + + XCTAssertEqual(a.cellReuseIdentifier, "CustomSwitchCell") + XCTAssertEqual(b.cellReuseIdentifier, "CustomSwitchCell.default") + XCTAssertEqual(c.cellReuseIdentifier, "CustomSwitchCell.subtitle") + XCTAssertEqual(d.cellReuseIdentifier, "CustomSwitchCell.value1") + XCTAssertEqual(e.cellReuseIdentifier, "CustomSwitchCell.value2") + } + // MARK: - Equatable func testEquatable_withIdenticalParameters() { diff --git a/Tests/Row/TapActionRowTests.swift b/Tests/Row/TapActionRowTests.swift index ae630fb3..c6a52c63 100644 --- a/Tests/Row/TapActionRowTests.swift +++ b/Tests/Row/TapActionRowTests.swift @@ -49,6 +49,15 @@ internal final class TapActionRowTests: XCTestCase { XCTAssertEqual(actionInvoked, true) } + func testCellStyleWithReuseIdentifier_customCellType() { + // When + let row = TapActionRow(text: "", action: { _ in }) + + // Then + XCTAssertEqual(row.cellStyle, .default) + XCTAssertEqual(row.cellReuseIdentifier, "CustomTapActionCell") + } + // MARK: - Equatable func testEquatable_withIdenticalParameters() { From 9d77076a6510c8b68ad0a75582bff2062669f506 Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 2 Jul 2020 22:41:31 +0100 Subject: [PATCH 3/3] Bump version to 1.2.4 --- .jazzy.yml | 4 ++-- CHANGELOG.md | 4 ++++ Example-iOS/Info.plist | 2 +- Example-iOSUITests/Info.plist | 2 +- Example-tvOS/Info.plist | 2 +- Example-tvOSUITests/Info.plist | 2 +- QuickTableViewController.podspec | 2 +- QuickTableViewController/Info-iOS.plist | 2 +- QuickTableViewController/Info-iOSTests.plist | 2 +- QuickTableViewController/Info-tvOS.plist | 2 +- QuickTableViewController/Info-tvOSTests.plist | 2 +- 11 files changed, 15 insertions(+), 11 deletions(-) diff --git a/.jazzy.yml b/.jazzy.yml index d39f41a7..dc487baa 100644 --- a/.jazzy.yml +++ b/.jazzy.yml @@ -2,14 +2,14 @@ clean: true author: bcylin author_url: https://github.com/bcylin github_url: https://github.com/bcylin/QuickTableViewController -github_file_prefix: https://github.com/bcylin/QuickTableViewController/blob/v1.2.3 +github_file_prefix: https://github.com/bcylin/QuickTableViewController/blob/v1.2.4 xcodebuild_arguments: [ -project, QuickTableViewController.xcodeproj, -scheme, QuickTableViewController-iOS, -sdk, iphonesimulator ] module: QuickTableViewController -module_version: 1.2.3 +module_version: 1.2.4 output: docs/output theme: fullwidth skip_undocumented: true diff --git a/CHANGELOG.md b/CHANGELOG.md index 1077e490..0b92b730 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## v1.2.4 + +* Fix an issue where the same identifier is used for different cell types [#50](https://github.com/bcylin/QuickTableViewController/issues/50) + ## v1.2.3 * Fix Swift version in podspec diff --git a/Example-iOS/Info.plist b/Example-iOS/Info.plist index 96bb2c4f..9977ac5e 100644 --- a/Example-iOS/Info.plist +++ b/Example-iOS/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.2.3 + 1.2.4 CFBundleVersion 101 LSRequiresIPhoneOS diff --git a/Example-iOSUITests/Info.plist b/Example-iOSUITests/Info.plist index 77b51ed6..b797526d 100644 --- a/Example-iOSUITests/Info.plist +++ b/Example-iOSUITests/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 1.2.3 + 1.2.4 CFBundleVersion 1 diff --git a/Example-tvOS/Info.plist b/Example-tvOS/Info.plist index 8c95e477..592164fd 100644 --- a/Example-tvOS/Info.plist +++ b/Example-tvOS/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.2.3 + 1.2.4 CFBundleVersion 101 LSRequiresIPhoneOS diff --git a/Example-tvOSUITests/Info.plist b/Example-tvOSUITests/Info.plist index 3fc9f5ed..1d45cf79 100644 --- a/Example-tvOSUITests/Info.plist +++ b/Example-tvOSUITests/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 1.2.3 + 1.2.4 CFBundleVersion 1 diff --git a/QuickTableViewController.podspec b/QuickTableViewController.podspec index a3df0d94..397d3386 100644 --- a/QuickTableViewController.podspec +++ b/QuickTableViewController.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "QuickTableViewController" - s.version = "1.2.3" + s.version = "1.2.4" s.summary = "A simple way to create a UITableView for settings." s.screenshots = "https://raw.githubusercontent.com/bcylin/QuickTableViewController/gh-pages/img/screenshot-1.png", "https://raw.githubusercontent.com/bcylin/QuickTableViewController/gh-pages/img/screenshot-2.png" diff --git a/QuickTableViewController/Info-iOS.plist b/QuickTableViewController/Info-iOS.plist index 6b6e8065..874145db 100644 --- a/QuickTableViewController/Info-iOS.plist +++ b/QuickTableViewController/Info-iOS.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.2.3 + 1.2.4 CFBundleSignature ???? CFBundleVersion diff --git a/QuickTableViewController/Info-iOSTests.plist b/QuickTableViewController/Info-iOSTests.plist index 0d0a175a..2243b9d4 100644 --- a/QuickTableViewController/Info-iOSTests.plist +++ b/QuickTableViewController/Info-iOSTests.plist @@ -15,7 +15,7 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 1.2.3 + 1.2.4 CFBundleSignature ???? CFBundleVersion diff --git a/QuickTableViewController/Info-tvOS.plist b/QuickTableViewController/Info-tvOS.plist index bdc7f0cd..a6b0794f 100644 --- a/QuickTableViewController/Info-tvOS.plist +++ b/QuickTableViewController/Info-tvOS.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.2.3 + 1.2.4 CFBundleVersion $(CURRENT_PROJECT_VERSION) NSPrincipalClass diff --git a/QuickTableViewController/Info-tvOSTests.plist b/QuickTableViewController/Info-tvOSTests.plist index 3fc9f5ed..1d45cf79 100644 --- a/QuickTableViewController/Info-tvOSTests.plist +++ b/QuickTableViewController/Info-tvOSTests.plist @@ -15,7 +15,7 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 1.2.3 + 1.2.4 CFBundleVersion 1