From 5102f4adf13bb234919706be006b29deede96d9f Mon Sep 17 00:00:00 2001 From: Anton Popkov Date: Thu, 12 Oct 2017 15:14:43 +0300 Subject: [PATCH] Remove type erasure from AnyBaseTableRow Rename AnyBaseTableRow to SeparatorRowBox --- LeadKit.xcodeproj/project.pbxproj | 18 +++++------ .../Views/EmptyCell/EmptyCellRow.swift | 6 ++-- .../SeparatorRowBox.swift} | 30 ++----------------- .../Array+AnyBaseTableRowExtensions.swift | 4 +-- .../TableDirector+Extensions.swift | 2 +- 5 files changed, 18 insertions(+), 42 deletions(-) rename Sources/Classes/Views/{AnyBaseTableRow/AnyBaseTableRow.swift => SeparatorRowBox/SeparatorRowBox.swift} (73%) diff --git a/LeadKit.xcodeproj/project.pbxproj b/LeadKit.xcodeproj/project.pbxproj index ed16ed59..39d3719f 100644 --- a/LeadKit.xcodeproj/project.pbxproj +++ b/LeadKit.xcodeproj/project.pbxproj @@ -402,10 +402,10 @@ A6E0DDDE1F8A696F002CA74E /* EmptyCellRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = A66428A71F8A654600C6308D /* EmptyCellRow.swift */; }; A6E0DDDF1F8A696F002CA74E /* SeparatorCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A66428A61F8A653600C6308D /* SeparatorCell.swift */; }; A6E0DDE01F8A696F002CA74E /* SeparatorCellViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A66428A51F8A653500C6308D /* SeparatorCellViewModel.swift */; }; - A6E0DDE11F8A696F002CA74E /* AnyBaseTableRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = A66428A81F8A655600C6308D /* AnyBaseTableRow.swift */; }; + A6E0DDE11F8A696F002CA74E /* SeparatorRowBox.swift in Sources */ = {isa = PBXBuildFile; fileRef = A66428A81F8A655600C6308D /* SeparatorRowBox.swift */; }; A6E0DDE31F8A696F002CA74E /* SeparatorCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A66428A61F8A653600C6308D /* SeparatorCell.swift */; }; A6E0DDE41F8A696F002CA74E /* SeparatorCellViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A66428A51F8A653500C6308D /* SeparatorCellViewModel.swift */; }; - A6E0DDE51F8A696F002CA74E /* AnyBaseTableRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = A66428A81F8A655600C6308D /* AnyBaseTableRow.swift */; }; + A6E0DDE51F8A696F002CA74E /* SeparatorRowBox.swift in Sources */ = {isa = PBXBuildFile; fileRef = A66428A81F8A655600C6308D /* SeparatorRowBox.swift */; }; A6E0DDEF1F8A6C57002CA74E /* CellSeparatorType.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6E0DDEE1F8A6C57002CA74E /* CellSeparatorType.swift */; }; A6E0DDF11F8A6C80002CA74E /* SeparatorConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6E0DDF01F8A6C80002CA74E /* SeparatorConfiguration.swift */; }; A6F32C081F6EBDAA00AC08EE /* String+LocalizedComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6F32C071F6EBDAA00AC08EE /* String+LocalizedComponent.swift */; }; @@ -605,7 +605,7 @@ A66428A51F8A653500C6308D /* SeparatorCellViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeparatorCellViewModel.swift; sourceTree = ""; }; A66428A61F8A653600C6308D /* SeparatorCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeparatorCell.swift; sourceTree = ""; }; A66428A71F8A654600C6308D /* EmptyCellRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyCellRow.swift; sourceTree = ""; }; - A66428A81F8A655600C6308D /* AnyBaseTableRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyBaseTableRow.swift; sourceTree = ""; }; + A66428A81F8A655600C6308D /* SeparatorRowBox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeparatorRowBox.swift; sourceTree = ""; }; A6AF3B361F8B956E00CDB971 /* EmptyCellViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyCellViewModel.swift; sourceTree = ""; }; A6AF3B371F8B956F00CDB971 /* EmptyCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyCell.swift; sourceTree = ""; }; A6D10EAA1F8A9278003E69DD /* Comparable+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Comparable+Extensions.swift"; sourceTree = ""; }; @@ -753,7 +753,7 @@ 671461D41EB3396E00EAB194 /* Views */ = { isa = PBXGroup; children = ( - A6AF3B381F8B957400CDB971 /* AnyBaseTableRow */, + A6AF3B381F8B957400CDB971 /* SeparatorRowBox */, A66428A41F8A651700C6308D /* SeparatorCell */, A6C9A4F71F8BBC0F009311CC /* EmptyCell */, A6C9A4F81F8BBC27009311CC /* SpinnerView */, @@ -1273,12 +1273,12 @@ path = SeparatorCell; sourceTree = ""; }; - A6AF3B381F8B957400CDB971 /* AnyBaseTableRow */ = { + A6AF3B381F8B957400CDB971 /* SeparatorRowBox */ = { isa = PBXGroup; children = ( - A66428A81F8A655600C6308D /* AnyBaseTableRow.swift */, + A66428A81F8A655600C6308D /* SeparatorRowBox.swift */, ); - path = AnyBaseTableRow; + path = SeparatorRowBox; sourceTree = ""; }; A6C9A4F71F8BBC0F009311CC /* EmptyCell */ = { @@ -2148,7 +2148,7 @@ 671462581EB3396E00EAB194 /* Log.swift in Sources */, 671462B41EB3396E00EAB194 /* PaginationTableViewWrapperDelegate+DefaultImplementation.swift in Sources */, 671462781EB3396E00EAB194 /* ResizeContentMode.swift in Sources */, - A6E0DDE11F8A696F002CA74E /* AnyBaseTableRow.swift in Sources */, + A6E0DDE11F8A696F002CA74E /* SeparatorRowBox.swift in Sources */, A6E0DDDE1F8A696F002CA74E /* EmptyCellRow.swift in Sources */, A6C9A4FB1F8BBCF2009311CC /* EmptyCellViewModel.swift in Sources */, 671463041EB3396E00EAB194 /* UIView+LoadingIndicator.swift in Sources */, @@ -2228,7 +2228,7 @@ A6E0DDE31F8A696F002CA74E /* SeparatorCell.swift in Sources */, A6C9A50F1F8BC79D009311CC /* Comparable+Extensions.swift in Sources */, 671463C41EB34B1E00EAB194 /* Post.swift in Sources */, - A6E0DDE51F8A696F002CA74E /* AnyBaseTableRow.swift in Sources */, + A6E0DDE51F8A696F002CA74E /* SeparatorRowBox.swift in Sources */, A6C9A5041F8BC78F009311CC /* CellSeparatorType.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Sources/Classes/Views/EmptyCell/EmptyCellRow.swift b/Sources/Classes/Views/EmptyCell/EmptyCellRow.swift index edb3da7b..04a0c529 100644 --- a/Sources/Classes/Views/EmptyCell/EmptyCellRow.swift +++ b/Sources/Classes/Views/EmptyCell/EmptyCellRow.swift @@ -50,9 +50,9 @@ public final class EmptyCellRow: TableRow { return item.height } - /// EmptyCellRow typed as AnyBaseTableRow - public var anyRow: AnyBaseTableRow { - return AnyBaseTableRow(tableRow: self) + /// EmptyCellRow typed as SeparatorRowBox + public var separatorRowBox: SeparatorRowBox { + return SeparatorRowBox(tableRow: self) } } diff --git a/Sources/Classes/Views/AnyBaseTableRow/AnyBaseTableRow.swift b/Sources/Classes/Views/SeparatorRowBox/SeparatorRowBox.swift similarity index 73% rename from Sources/Classes/Views/AnyBaseTableRow/AnyBaseTableRow.swift rename to Sources/Classes/Views/SeparatorRowBox/SeparatorRowBox.swift index 70810c57..06133398 100644 --- a/Sources/Classes/Views/AnyBaseTableRow/AnyBaseTableRow.swift +++ b/Sources/Classes/Views/SeparatorRowBox/SeparatorRowBox.swift @@ -22,43 +22,19 @@ import TableKit -/// Class used as general placeholder for type-erasured in TableRow -private class AnyBaseTableRowHolder { - let row: Row - - init(tableRow: Row) { - row = tableRow - } -} - -/// Class used to hold resolved TableRow -private final class AnyBaseTableRowBox: AnyBaseTableRowHolder - where T: SeparatorCell, T.T: SeparatorCellViewModel { - - init(tableRow: TableRow) { - super.init(tableRow: tableRow) - } - -} - /// Class that used to configure separators when multiply cells presented in one section /// Holds TableRow with any model inherited from BaseCellViewModel -public final class AnyBaseTableRow { - - private let anyTableRow: AnyBaseTableRowHolder - +public final class SeparatorRowBox { /// Row `item`, that typed as BaseCellViewModel public let viewModel: SeparatorCellViewModel /// TableRow that typed to generic Row - public var row: Row { - return anyTableRow.row - } + public let row: Row /// Initialize AnyBaseTableRow with tableRow /// - parameter tableRow: TableRow which `item` conforms to BaseCellViewModel public init(tableRow: TableRow) where T: SeparatorCell, T.T: SeparatorCellViewModel { - anyTableRow = AnyBaseTableRowBox(tableRow: tableRow) + row = tableRow viewModel = tableRow.item } diff --git a/Sources/Extensions/Array/Array+AnyBaseTableRowExtensions.swift b/Sources/Extensions/Array/Array+AnyBaseTableRowExtensions.swift index 2a66cc04..4f5228ff 100644 --- a/Sources/Extensions/Array/Array+AnyBaseTableRowExtensions.swift +++ b/Sources/Extensions/Array/Array+AnyBaseTableRowExtensions.swift @@ -22,9 +22,9 @@ import TableKit -public extension Array where Element == AnyBaseTableRow { +public extension Array where Element == SeparatorRowBox { - /// Create rows from anyBaseTableRow array + /// Create rows from SeparatorRowBox array var rows: [Row] { return map { $0.row } } diff --git a/Sources/Extensions/TableDirector/TableDirector+Extensions.swift b/Sources/Extensions/TableDirector/TableDirector+Extensions.swift index 2010e557..b998eaed 100644 --- a/Sources/Extensions/TableDirector/TableDirector+Extensions.swift +++ b/Sources/Extensions/TableDirector/TableDirector+Extensions.swift @@ -121,7 +121,7 @@ public extension TableDirector { /// - parameter rows: Rows for configuration /// - parameter extreme: Configuration that will be used for extreme values, for first or last row /// - parameter middle: Configuration for intermediate rows - func configure(rows: [AnyBaseTableRow], + func configure(rows: [SeparatorRowBox], extreme extremeSeparatorConfiguration: SeparatorConfiguration, middle middleSeparatorConfiguration: SeparatorConfiguration) {