use @discardableResult to suppress warnings

This commit is contained in:
Max Sokolov 2016-10-04 20:10:09 +03:00
parent 5db9726dab
commit a88043b33a
4 changed files with 24 additions and 15 deletions

View File

@ -28,6 +28,6 @@ class NibCellsController: UITableViewController {
let rows: [Row] = numbers.map { TableRow<Int, NibTableViewCell>(item: $0, actions: [shouldHighlightAction]) }
_ = tableDirector.append(rows: rows)
tableDirector.append(rows: rows)
}
}

View File

@ -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)
}

View File

@ -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()

View File

@ -107,12 +107,14 @@ open class TableRow<ItemType, CellType: ConfigurableCell>: Row where CellType.T
// MARK: - actions -
@discardableResult
open func action(_ action: TableRowAction<ItemType, CellType>) -> Self {
actions[action.type.key] = action
return self
}
@discardableResult
open func action<T>(_ type: TableRowActionType, handler: @escaping (_ data: TableRowActionData<ItemType, CellType>) -> T) -> Self {
actions[type.key] = TableRowAction<ItemType, CellType>(type, handler: handler)