From a240acee2d4d80132d7b0a372644d9edbe7ec9f6 Mon Sep 17 00:00:00 2001 From: Max Sokolov Date: Fri, 14 Oct 2016 20:35:18 +0300 Subject: [PATCH] deprecate action method on TableRow, add on instead --- .../Controllers/NibCellsController.swift | 11 ++++++----- Sources/TableRow.swift | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Demo/Classes/Presentation/Controllers/NibCellsController.swift b/Demo/Classes/Presentation/Controllers/NibCellsController.swift index 32736a6..544a095 100644 --- a/Demo/Classes/Presentation/Controllers/NibCellsController.swift +++ b/Demo/Classes/Presentation/Controllers/NibCellsController.swift @@ -21,12 +21,13 @@ class NibCellsController: UITableViewController { tableDirector = TableDirector(tableView: tableView) let numbers = [1000, 2000, 3000, 4000, 5000] - - let shouldHighlightAction = TableRowAction(.shouldHighlight) { (_) -> Bool in - return false - } - let rows = numbers.map { TableRow(item: $0, actions: [shouldHighlightAction]) } + let rows = numbers.map { + TableRow(item: $0) + .on(.shouldHighlight) { (_) -> Bool in + return false + } + } tableDirector.append(rows: rows) } diff --git a/Sources/TableRow.swift b/Sources/TableRow.swift index 6cf3738..b05cada 100644 --- a/Sources/TableRow.swift +++ b/Sources/TableRow.swift @@ -107,6 +107,23 @@ open class TableRow: Row where CellType: UITableView // MARK: - actions - + @discardableResult + open func on(_ action: TableRowAction) -> Self { + + actions[action.type.key] = action + return self + } + + @discardableResult + open func on(_ type: TableRowActionType, handler: @escaping (_ data: TableRowActionData) -> T) -> Self { + + actions[type.key] = TableRowAction(type, handler: handler) + return self + } + + // MARK: - deprecated actions - + + @available(*, deprecated, message: "Use 'on' method instead") @discardableResult open func action(_ action: TableRowAction) -> Self { @@ -114,6 +131,7 @@ open class TableRow: Row where CellType: UITableView return self } + @available(*, deprecated, message: "Use 'on' method instead") @discardableResult open func action(_ type: TableRowActionType, handler: @escaping (_ data: TableRowActionData) -> T) -> Self {