From 6f441b2f7d763d4d5e58ba352bf91ce97b974be6 Mon Sep 17 00:00:00 2001 From: Max Sokolov Date: Thu, 6 Oct 2016 01:45:39 +0300 Subject: [PATCH] reduce first generic parameter --- .../AutolayoutCellsController.swift | 4 ++-- .../Controllers/MainController.swift | 6 ++--- .../Controllers/NibCellsController.swift | 4 ++-- Sources/TableRow.swift | 14 +++++------ Sources/TableRowAction.swift | 24 +++++++++---------- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Demo/Classes/Presentation/Controllers/AutolayoutCellsController.swift b/Demo/Classes/Presentation/Controllers/AutolayoutCellsController.swift index 9340070..9d9d3ad 100644 --- a/Demo/Classes/Presentation/Controllers/AutolayoutCellsController.swift +++ b/Demo/Classes/Presentation/Controllers/AutolayoutCellsController.swift @@ -30,10 +30,10 @@ class AutolayoutCellsController: UIViewController { while rows <= 1000 { rows += 1 - let row = TableRow(item: ()) + let row = TableRow(item: ()) section += row } tableDirector += section } -} \ No newline at end of file +} diff --git a/Demo/Classes/Presentation/Controllers/MainController.swift b/Demo/Classes/Presentation/Controllers/MainController.swift index dfb92c7..7c0afdd 100644 --- a/Demo/Classes/Presentation/Controllers/MainController.swift +++ b/Demo/Classes/Presentation/Controllers/MainController.swift @@ -23,7 +23,7 @@ class MainController: UIViewController { title = "TableKit" - let clickAction = TableRowAction(.click) { [weak self] (data) in + let clickAction = TableRowAction(.click) { [weak self] (data) in switch (data.indexPath as NSIndexPath).row { case 0: @@ -37,8 +37,8 @@ class MainController: UIViewController { let rows = [ - TableRow(item: "Autolayout cells", actions: [clickAction]), - TableRow(item: "Nib cells", actions: [clickAction]) + TableRow(item: "Autolayout cells", actions: [clickAction]), + TableRow(item: "Nib cells", actions: [clickAction]) ] // automatically creates a section, also could be used like tableDirector.append(rows: rows) diff --git a/Demo/Classes/Presentation/Controllers/NibCellsController.swift b/Demo/Classes/Presentation/Controllers/NibCellsController.swift index 082af9c..32736a6 100644 --- a/Demo/Classes/Presentation/Controllers/NibCellsController.swift +++ b/Demo/Classes/Presentation/Controllers/NibCellsController.swift @@ -22,11 +22,11 @@ class NibCellsController: UITableViewController { let numbers = [1000, 2000, 3000, 4000, 5000] - let shouldHighlightAction = TableRowAction(.shouldHighlight) { (_) -> Bool in + let shouldHighlightAction = TableRowAction(.shouldHighlight) { (_) -> Bool in return false } - let rows: [Row] = numbers.map { TableRow(item: $0, actions: [shouldHighlightAction]) } + let rows = numbers.map { TableRow(item: $0, actions: [shouldHighlightAction]) } tableDirector.append(rows: rows) } diff --git a/Sources/TableRow.swift b/Sources/TableRow.swift index bc40ec3..6cf3738 100644 --- a/Sources/TableRow.swift +++ b/Sources/TableRow.swift @@ -48,10 +48,10 @@ public protocol Row: RowConfigurable, RowActionable, RowHashable { var defaultHeight: CGFloat? { get } } -open class TableRow: Row where CellType.T == ItemType, CellType: UITableViewCell { +open class TableRow: Row where CellType: UITableViewCell { - open let item: ItemType - private lazy var actions = [String: TableRowAction]() + open let item: CellType.T + private lazy var actions = [String: TableRowAction]() private(set) open var editingActions: [UITableViewRowAction]? open var hashValue: Int { @@ -74,7 +74,7 @@ open class TableRow: Row where CellType.T return CellType.self } - public init(item: ItemType, actions: [TableRowAction]? = nil, editingActions: [UITableViewRowAction]? = nil) { + public init(item: CellType.T, actions: [TableRowAction]? = nil, editingActions: [UITableViewRowAction]? = nil) { self.item = item self.editingActions = editingActions @@ -108,16 +108,16 @@ open class TableRow: Row where CellType.T // MARK: - actions - @discardableResult - open func action(_ action: TableRowAction) -> Self { + open func action(_ action: TableRowAction) -> Self { actions[action.type.key] = action return self } @discardableResult - open func action(_ type: TableRowActionType, handler: @escaping (_ data: TableRowActionData) -> T) -> Self { + open func action(_ type: TableRowActionType, handler: @escaping (_ data: TableRowActionData) -> T) -> Self { - actions[type.key] = TableRowAction(type, handler: handler) + actions[type.key] = TableRowAction(type, handler: handler) return self } } diff --git a/Sources/TableRowAction.swift b/Sources/TableRowAction.swift index dac4b49..2533b6a 100644 --- a/Sources/TableRowAction.swift +++ b/Sources/TableRowAction.swift @@ -45,14 +45,14 @@ public enum TableRowActionType { } } -open class TableRowActionData where CellType.T == ItemType, CellType: UITableViewCell { +open class TableRowActionData where CellType: UITableViewCell { - open let item: ItemType + open let item: CellType.T open let cell: CellType? open let indexPath: IndexPath open let userInfo: [AnyHashable: Any]? - init(item: ItemType, cell: CellType?, path: IndexPath, userInfo: [AnyHashable: Any]?) { + init(item: CellType.T, cell: CellType?, path: IndexPath, userInfo: [AnyHashable: Any]?) { self.item = item self.cell = cell @@ -61,12 +61,12 @@ open class TableRowActionData where CellTy } } -private enum TableRowActionHandler where CellType.T == ItemType, CellType: UITableViewCell { +private enum TableRowActionHandler where CellType: UITableViewCell { - case voidAction((TableRowActionData) -> Void) - case action((TableRowActionData) -> Any?) + case voidAction((TableRowActionData) -> Void) + case action((TableRowActionData) -> Any?) - func invoke(item: ItemType, cell: UITableViewCell?, path: IndexPath) -> Any? { + func invoke(item: CellType.T, cell: UITableViewCell?, path: IndexPath) -> Any? { switch self { case .voidAction(let handler): @@ -77,24 +77,24 @@ private enum TableRowActionHandler where C } } -open class TableRowAction where CellType.T == ItemType, CellType: UITableViewCell { +open class TableRowAction where CellType: UITableViewCell { open let type: TableRowActionType - private let handler: TableRowActionHandler + private let handler: TableRowActionHandler - public init(_ type: TableRowActionType, handler: @escaping (_ data: TableRowActionData) -> Void) { + public init(_ type: TableRowActionType, handler: @escaping (_ data: TableRowActionData) -> Void) { self.type = type self.handler = .voidAction(handler) } - public init(_ type: TableRowActionType, handler: @escaping (_ data: TableRowActionData) -> T) { + public init(_ type: TableRowActionType, handler: @escaping (_ data: TableRowActionData) -> T) { self.type = type self.handler = .action(handler) } - func invoke(item: ItemType, cell: UITableViewCell?, path: IndexPath) -> Any? { + func invoke(item: CellType.T, cell: UITableViewCell?, path: IndexPath) -> Any? { return handler.invoke(item: item, cell: cell, path: path) } }