From 32a257149e65f06d44ca4199de1ca46684f1c514 Mon Sep 17 00:00:00 2001 From: Max Sokolov Date: Mon, 2 May 2016 22:03:52 +0300 Subject: [PATCH] some refactoring --- Tablet/TableRowBuilder.swift | 40 ++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Tablet/TableRowBuilder.swift b/Tablet/TableRowBuilder.swift index 6ed6869..b3429d2 100644 --- a/Tablet/TableRowBuilder.swift +++ b/Tablet/TableRowBuilder.swift @@ -23,19 +23,19 @@ import Foundation public typealias ReturnValue = AnyObject? -enum ActionHandler { - - case actionBlock((data: ActionData) -> Void) - case actionReturnBlock((data: ActionData) -> AnyObject?) - - func invoke(data: ActionData) -> ReturnValue { - +enum ActionHandler { + + case Handler((data: ActionData) -> Void) + case ReturnValueHandler((data: ActionData) -> AnyObject?) + + func invoke(data: ActionData) -> ReturnValue { + switch (self) { - case .actionBlock(let closure): - closure(data: data) + case .Handler(let handler): + handler(data: data) return true - case .actionReturnBlock(let closure): - return closure(data: data) + case .ReturnValueHandler(let handler): + return handler(data: data) } } } @@ -69,7 +69,7 @@ public class RowBuilder : NSObject { */ public class TableRowBuilder : RowBuilder { - private var actions = Dictionary>() + private var actions = [String: ActionHandler]() private var items = [DataType]() public override var numberOfRows: Int { @@ -92,29 +92,29 @@ public class TableRowBuilder // MARK: Chaining actions - public func action(key: String, closure: (data: ActionData) -> Void) -> Self { + public func action(key: String, handler: (data: ActionData) -> Void) -> Self { - actions[key] = .actionBlock(closure) + actions[key] = .Handler(handler) return self } - public func action(actionType: ActionType, closure: (data: ActionData) -> Void) -> Self { + public func action(type: ActionType, handler: (data: ActionData) -> Void) -> Self { - actions[actionType.key] = .actionBlock(closure) + actions[type.key] = .Handler(handler) return self } - public func action(actionType: ActionType, closure: (data: ActionData) -> ReturnValue) -> Self { + public func action(type: ActionType, handler: (data: ActionData) -> ReturnValue) -> Self { - actions[actionType.key] = .actionReturnBlock(closure) + actions[type.key] = .ReturnValueHandler(handler) return self } // MARK: Internal - override func invokeAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int, userInfo: [NSObject: AnyObject]?) -> AnyObject? { + override func invokeAction(type: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int, userInfo: [NSObject: AnyObject]?) -> AnyObject? { - if let action = actions[actionType.key] { + if let action = actions[type.key] { return action.invoke(ActionData(cell: cell as? CellType, indexPath: indexPath, item: items[itemIndex], itemIndex: itemIndex, userInfo: userInfo)) } return nil