diff --git a/Demo/Classes/Presentation/Controllers/NibCellsController.swift b/Demo/Classes/Presentation/Controllers/NibCellsController.swift index e4edd0b..082af9c 100644 --- a/Demo/Classes/Presentation/Controllers/NibCellsController.swift +++ b/Demo/Classes/Presentation/Controllers/NibCellsController.swift @@ -28,6 +28,6 @@ class NibCellsController: UITableViewController { let rows: [Row] = numbers.map { TableRow(item: $0, actions: [shouldHighlightAction]) } - _ = tableDirector.append(rows: rows) + tableDirector.append(rows: rows) } } diff --git a/Sources/Operators.swift b/Sources/Operators.swift index f4e719d..9d4b96e 100644 --- a/Sources/Operators.swift +++ b/Sources/Operators.swift @@ -20,27 +20,27 @@ // -- public func +=(left: TableDirector, right: TableSection) { - _ = left.append(section: right) + left.append(section: right) } public func +=(left: TableDirector, right: [TableSection]) { - _ = left.append(sections: right) + left.append(sections: right) } // -- public func +=(left: TableDirector, right: Row) { - _ = left.append(sections: [TableSection(rows: [right])]) + left.append(sections: [TableSection(rows: [right])]) } public func +=(left: TableDirector, right: [Row]) { - _ = left.append(sections: [TableSection(rows: right)]) + left.append(sections: [TableSection(rows: right)]) } // -- public func +=(left: TableSection, right: Row) { - _ = left.append(row: right) + left.append(row: right) } public func +=(left: TableSection, right: [Row]) { - _ = left.append(rows: right) + left.append(rows: right) } diff --git a/Sources/TableDirector.swift b/Sources/TableDirector.swift index 3cda756..be857c6 100644 --- a/Sources/TableDirector.swift +++ b/Sources/TableDirector.swift @@ -69,6 +69,7 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { // MARK: Public + @discardableResult open func invoke(action: TableRowActionType, cell: UITableViewCell?, indexPath: IndexPath) -> Any? { return sections[(indexPath as NSIndexPath).section].rows[(indexPath as NSIndexPath).row].invoke(action, cell: cell, path: indexPath) } @@ -90,7 +91,7 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { func didReceiveAction(_ notification: Notification) { guard let action = notification.object as? TableCellAction, let indexPath = tableView?.indexPath(for: action.cell) else { return } - _ = invoke(action: .custom(action.key), cell: action.cell, indexPath: indexPath) + invoke(action: .custom(action.key), cell: action.cell, indexPath: indexPath) } // MARK: - Height @@ -134,7 +135,7 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { } row.configure(cell) - _ = invoke(action: .configure, cell: cell, indexPath: indexPath) + invoke(action: .configure, cell: cell, indexPath: indexPath) return cell } @@ -180,16 +181,16 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { if invoke(action: .click, cell: cell, indexPath: indexPath) != nil { tableView.deselectRow(at: indexPath, animated: true) } else { - _ = invoke(action: .select, cell: cell, indexPath: indexPath) + invoke(action: .select, cell: cell, indexPath: indexPath) } } open func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) { - _ = invoke(action: .deselect, cell: tableView.cellForRow(at: indexPath), indexPath: indexPath) + invoke(action: .deselect, cell: tableView.cellForRow(at: indexPath), indexPath: indexPath) } open func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { - _ = invoke(action: .willDisplay, cell: cell, indexPath: indexPath) + invoke(action: .willDisplay, cell: cell, indexPath: indexPath) } open func tableView(_ tableView: UITableView, shouldHighlightRowAt indexPath: IndexPath) -> Bool { @@ -217,42 +218,48 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { open func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { if editingStyle == .delete { - _ = invoke(action: .clickDelete, cell: tableView.cellForRow(at: indexPath), indexPath: indexPath) + invoke(action: .clickDelete, cell: tableView.cellForRow(at: indexPath), indexPath: indexPath) } } // MARK: - Sections manipulation - + @discardableResult open func append(section: TableSection) -> Self { - _ = append(sections: [section]) + append(sections: [section]) return self } + @discardableResult open func append(sections: [TableSection]) -> Self { self.sections.append(contentsOf: sections) return self } + @discardableResult open func append(rows: [Row]) -> Self { - _ = append(section: TableSection(rows: rows)) + append(section: TableSection(rows: rows)) return self } + @discardableResult open func insert(section: TableSection, atIndex index: Int) -> Self { sections.insert(section, at: index) return self } + @discardableResult open func delete(index: Int) -> Self { sections.remove(at: index) return self } + @discardableResult open func clear() -> Self { sections.removeAll() diff --git a/Sources/TableRow.swift b/Sources/TableRow.swift index ad440b3..bc40ec3 100644 --- a/Sources/TableRow.swift +++ b/Sources/TableRow.swift @@ -107,12 +107,14 @@ open class TableRow: Row where CellType.T // MARK: - actions - + @discardableResult 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 { actions[type.key] = TableRowAction(type, handler: handler)