diff --git a/Sources/TableCellAction.swift b/Sources/TableCellAction.swift index 0e30413..b962dab 100644 --- a/Sources/TableCellAction.swift +++ b/Sources/TableCellAction.swift @@ -20,10 +20,6 @@ import UIKit -struct TableKitNotifications { - static let CellAction = "TableKitNotificationsCellAction" -} - /** A custom action that you can trigger from your cell. You can easily catch actions using a chaining manner with your row. diff --git a/Sources/TableKit.swift b/Sources/TableKit.swift index 30681d9..bff0ef4 100644 --- a/Sources/TableKit.swift +++ b/Sources/TableKit.swift @@ -20,6 +20,10 @@ import UIKit +struct TableKitNotifications { + static let CellAction = "TableKitNotificationsCellAction" +} + public protocol RowConfigurable { func configure(_ cell: UITableViewCell) @@ -29,8 +33,7 @@ public protocol RowActionable { var editingActions: [UITableViewRowAction]? { get } func isEditingAllowed(forIndexPath indexPath: IndexPath) -> Bool - - func on(anyAction action: RowAction) -> Self + func invoke(action: TableRowActionType, cell: UITableViewCell?, path: IndexPath, userInfo: [AnyHashable: Any]?) -> Any? func has(action: TableRowActionType) -> Bool } @@ -74,14 +77,6 @@ public enum TableRowActionType { } } -public protocol RowAction { - - var id: String? { get set } - var type: TableRowActionType { get } - - func invokeActionOn(cell: UITableViewCell?, item: Any, path: IndexPath, userInfo: [AnyHashable: Any]?) -> Any? -} - public protocol RowHeightCalculator { func height(forRow row: Row, at indexPath: IndexPath) -> CGFloat diff --git a/Sources/TableRow.swift b/Sources/TableRow.swift index d23c7f2..631768c 100644 --- a/Sources/TableRow.swift +++ b/Sources/TableRow.swift @@ -23,7 +23,7 @@ import UIKit open class TableRow: Row where CellType: UITableViewCell { open let item: CellType.T - private lazy var actions = [String: [RowAction]]() + private lazy var actions = [String: [TableRowAction]]() private(set) open var editingActions: [UITableViewRowAction]? open var hashValue: Int { @@ -85,7 +85,12 @@ open class TableRow: Row where CellType: UITableView @discardableResult open func on(_ action: TableRowAction) -> Self { - return on(anyAction: action) + if actions[action.type.key] == nil { + actions[action.type.key] = [TableRowAction]() + } + actions[action.type.key]?.append(action) + + return self } @discardableResult @@ -93,18 +98,7 @@ open class TableRow: Row where CellType: UITableView return on(TableRowAction(type, handler: handler)) } - - @discardableResult - open func on(anyAction action: RowAction) -> Self { - if actions[action.type.key] == nil { - actions[action.type.key] = [RowAction]() - } - actions[action.type.key]?.append(action) - - return self - } - open func removeAllActions() { actions.removeAll() diff --git a/Sources/TableRowAction.swift b/Sources/TableRowAction.swift index 9d9be52..ad92bb4 100644 --- a/Sources/TableRowAction.swift +++ b/Sources/TableRowAction.swift @@ -53,7 +53,7 @@ private enum TableRowActionHandler where CellType: U } } -open class TableRowAction: RowAction where CellType: UITableViewCell { +open class TableRowAction where CellType: UITableViewCell { open var id: String? open let type: TableRowActionType diff --git a/Sources/TableRowAnyAction.swift b/Sources/TableRowAnyAction.swift deleted file mode 100644 index 85515ec..0000000 --- a/Sources/TableRowAnyAction.swift +++ /dev/null @@ -1,30 +0,0 @@ -// -// TableRowAnyAction.swift -// TableKit -// -// Created by Max Sokolov on 18/10/16. -// Copyright © 2016 Max Sokolov. All rights reserved. -// - -import UIKit - -open class TableRowAnyActionOptions { - - -} - -open class TableRowAnyAction { - - open var id: String? - open let type: TableRowActionType - - init(_ type: TableRowActionType, handler: @escaping () -> ()) { - - self.type = type - } - - func invoke(cell: UITableViewCell?, item: Any, path: IndexPath, userInfo: [AnyHashable: Any]?) -> Any? { - - return nil - } -} diff --git a/TableKit.xcodeproj/project.pbxproj b/TableKit.xcodeproj/project.pbxproj index 05181b0..c2ace6d 100644 --- a/TableKit.xcodeproj/project.pbxproj +++ b/TableKit.xcodeproj/project.pbxproj @@ -7,7 +7,6 @@ objects = { /* Begin PBXBuildFile section */ - 50826A001DB694CF002AABB5 /* TableRowAnyAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 508269FF1DB694CF002AABB5 /* TableRowAnyAction.swift */; }; 50CF6E6B1D6704FE004746FF /* TableCellRegisterer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50CF6E6A1D6704FE004746FF /* TableCellRegisterer.swift */; }; 50E858581DB153F500A9AA55 /* TableKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E858571DB153F500A9AA55 /* TableKit.swift */; }; DA9EA7AF1D0EC2C90021F650 /* ConfigurableCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA9EA7A61D0EC2C90021F650 /* ConfigurableCell.swift */; }; @@ -33,7 +32,6 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 508269FF1DB694CF002AABB5 /* TableRowAnyAction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableRowAnyAction.swift; sourceTree = ""; }; 50CF6E6A1D6704FE004746FF /* TableCellRegisterer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableCellRegisterer.swift; sourceTree = ""; }; 50E858571DB153F500A9AA55 /* TableKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableKit.swift; sourceTree = ""; }; DA9EA7561D0B679A0021F650 /* TableKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TableKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -96,7 +94,6 @@ DA9EA7AA1D0EC2C90021F650 /* TableDirector.swift */, 50CF6E6A1D6704FE004746FF /* TableCellRegisterer.swift */, DA9EA7AB1D0EC2C90021F650 /* TableRow.swift */, - 508269FF1DB694CF002AABB5 /* TableRowAnyAction.swift */, DA9EA7AC1D0EC2C90021F650 /* TableRowAction.swift */, DA9EA7AE1D0EC2C90021F650 /* TableSection.swift */, DA9EA7A91D0EC2C90021F650 /* TableCellAction.swift */, @@ -240,7 +237,6 @@ DA9EA7B01D0EC2C90021F650 /* TablePrototypeCellHeightCalculator.swift in Sources */, DA9EA7B51D0EC2C90021F650 /* TableRowAction.swift in Sources */, DA9EA7B21D0EC2C90021F650 /* TableCellAction.swift in Sources */, - 50826A001DB694CF002AABB5 /* TableRowAnyAction.swift in Sources */, DA9EA7B11D0EC2C90021F650 /* Operators.swift in Sources */, DA9EA7B41D0EC2C90021F650 /* TableRow.swift in Sources */, 50E858581DB153F500A9AA55 /* TableKit.swift in Sources */,