diff --git a/README.md b/README.md index d23abe9..6193aaa 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ You may want to setup a very basic table view, without any custom cells. In that import Tablet let rowBuilder = TableRowBuilder(items: [user1, user2, user3], id: "reusable_id") - .action(.configure) { data in + .action(.configure) { data -> Void in data.cell?.textLabel?.text = data.item.username data.cell?.detailTextLabel?.text = data.item.isActive ? "Active" : "Inactive" @@ -104,13 +104,13 @@ Tablet provides a chaining approach to handle actions from your cells: import Tablet let rowBuilder = TableRowBuilder(items: [user1, user2, user3], id: "reusable_id") - .action(.configure) { data in + .action(.configure) { data -> Void in } - .action(.click) { data in + .action(.click) { data -> Void in } - .action(.shouldHighlight) { data in + .action(.shouldHighlight) { data -> ReturnValue in return false } @@ -126,7 +126,7 @@ class MyTableViewCell : UITableViewCell { @IBAction func buttonClicked(sender: UIButton) { - Action(key: kMyAction, sender: self, userInfo: nil).perform() + Action(key: kMyAction, sender: self, userInfo: nil).invoke() } } ``` @@ -135,13 +135,13 @@ And receive this actions with your row builder: import Tablet let rowBuilder = TableConfigurableRowBuilder(items: users, id: "reusable_id", estimatedRowHeight: 42) - .action(.click) { data in + .action(.click) { data -> Void in } - .action(.willDisplay) { data in + .action(.willDisplay) { data -> Void in } - .action(kMyAction) { data in + .action(kMyAction) { data -> Void in } ``` @@ -159,18 +159,18 @@ extension TableDirector { public func tableView(tableView: UITableView, didEndDisplayingCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { - performAction(.custom(kTableDirectorDidEndDisplayingCell), cell: cell, indexPath: indexPath) + invokeAction(.custom(kTableDirectorDidEndDisplayingCell), cell: cell, indexPath: indexPath) } } ``` Catch your action with row builder: ```swift let rowBuilder = TableConfigurableRowBuilder(items: users, estimatedRowHeight: 42) - .action(kTableDirectorDidEndDisplayingCell) { data in + .action(kTableDirectorDidEndDisplayingCell) { data -> Void in } ``` -You could also perform an action that returns a value. +You could also invoke an action that returns a value. ## License diff --git a/Tablet/TableDirector.swift b/Tablet/TableDirector.swift index 30c6daf..41498bb 100644 --- a/Tablet/TableDirector.swift +++ b/Tablet/TableDirector.swift @@ -69,10 +69,10 @@ public class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate return sections[indexPath.section].builderAtIndex(indexPath.row)! } - public func performAction(action: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath) -> AnyObject? { + public func invokeAction(action: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath) -> AnyObject? { let builder = builderAtIndexPath(indexPath) - return builder.0.performAction(action, cell: cell, indexPath: indexPath, itemIndex: builder.1) + return builder.0.invokeAction(action, cell: cell, indexPath: indexPath, itemIndex: builder.1) } internal func didReceiveAction(notification: NSNotification) { @@ -80,7 +80,7 @@ public class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate if let action = notification.object as? Action, indexPath = tableView.indexPathForCell(action.cell) { let builder = builderAtIndexPath(indexPath) - builder.0.performAction(.custom(action.key), cell: action.cell, indexPath: indexPath, itemIndex: builder.1) + builder.0.invokeAction(.custom(action.key), cell: action.cell, indexPath: indexPath, itemIndex: builder.1) } } @@ -102,7 +102,7 @@ public class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate let cell = tableView.dequeueReusableCellWithIdentifier(builder.0.reusableIdentifier, forIndexPath: indexPath) - builder.0.performAction(.configure, cell: cell, indexPath: indexPath, itemIndex: builder.1) + builder.0.invokeAction(.configure, cell: cell, indexPath: indexPath, itemIndex: builder.1) return cell } @@ -156,32 +156,32 @@ extension TableDirector { public func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { - return performAction(.height, cell: nil, indexPath: indexPath) as? CGFloat ?? UITableViewAutomaticDimension + return invokeAction(.height, cell: nil, indexPath: indexPath) as? CGFloat ?? UITableViewAutomaticDimension } public func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { let cell = tableView.cellForRowAtIndexPath(indexPath) - if performAction(.click, cell: cell, indexPath: indexPath) != nil { + if invokeAction(.click, cell: cell, indexPath: indexPath) != nil { tableView.deselectRowAtIndexPath(indexPath, animated: true) } else { - performAction(.select, cell: cell, indexPath: indexPath) + invokeAction(.select, cell: cell, indexPath: indexPath) } } public func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) { - performAction(.deselect, cell: tableView.cellForRowAtIndexPath(indexPath), indexPath: indexPath) + invokeAction(.deselect, cell: tableView.cellForRowAtIndexPath(indexPath), indexPath: indexPath) } public func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { - performAction(.willDisplay, cell: cell, indexPath: indexPath) + invokeAction(.willDisplay, cell: cell, indexPath: indexPath) } public func tableView(tableView: UITableView, shouldHighlightRowAtIndexPath indexPath: NSIndexPath) -> Bool { - return performAction(.shouldHighlight, cell: tableView.cellForRowAtIndexPath(indexPath), indexPath: indexPath) as? Bool ?? true + return invokeAction(.shouldHighlight, cell: tableView.cellForRowAtIndexPath(indexPath), indexPath: indexPath) as? Bool ?? true } } \ No newline at end of file diff --git a/Tablet/TableRowBuilder.swift b/Tablet/TableRowBuilder.swift index edd2854..016fa2a 100644 --- a/Tablet/TableRowBuilder.swift +++ b/Tablet/TableRowBuilder.swift @@ -107,7 +107,7 @@ public class TableRowBuilder : RowBuilder { // MARK: Triggers - public func performAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int) -> AnyObject? { + public func invokeAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int) -> AnyObject? { if let action = actions[actionType.key] { return action.call(ActionData(cell: cell as? C, indexPath: indexPath, item: items[itemIndex], itemIndex: itemIndex)) @@ -129,13 +129,13 @@ public class TableConfigurableRowBuilder AnyObject? { + public override func invokeAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int) -> AnyObject? { switch actionType { case .configure: (cell as? C)?.configureWithItem(items[itemIndex]) default: break } - return super.performAction(actionType, cell: cell, indexPath: indexPath, itemIndex: itemIndex) + return super.invokeAction(actionType, cell: cell, indexPath: indexPath, itemIndex: itemIndex) } } diff --git a/Tablet/Tablet.swift b/Tablet/Tablet.swift index 3331c53..698cd50 100644 --- a/Tablet/Tablet.swift +++ b/Tablet/Tablet.swift @@ -86,7 +86,7 @@ public class Action { self.userInfo = userInfo } - public func perform() { + public func invoke() { NSNotificationCenter.defaultCenter().postNotificationName(kActionPerformedNotificationKey, object: self) } @@ -114,5 +114,5 @@ public protocol RowBuilder { var reusableIdentifier: String { get } var estimatedRowHeight: CGFloat { get } - func performAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int) -> AnyObject? + func invokeAction(actionType: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int) -> AnyObject? } \ No newline at end of file diff --git a/TabletDemo/TabletDemo.xcodeproj/project.xcworkspace/xcuserdata/maxsokolov.xcuserdatad/UserInterfaceState.xcuserstate b/TabletDemo/TabletDemo.xcodeproj/project.xcworkspace/xcuserdata/maxsokolov.xcuserdatad/UserInterfaceState.xcuserstate index 37a26d5..479978b 100644 Binary files a/TabletDemo/TabletDemo.xcodeproj/project.xcworkspace/xcuserdata/maxsokolov.xcuserdatad/UserInterfaceState.xcuserstate and b/TabletDemo/TabletDemo.xcodeproj/project.xcworkspace/xcuserdata/maxsokolov.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/TabletDemo/TabletDemo/ConfigurableTableViewCell.swift b/TabletDemo/TabletDemo/ConfigurableTableViewCell.swift index 07be0a2..215a443 100644 --- a/TabletDemo/TabletDemo/ConfigurableTableViewCell.swift +++ b/TabletDemo/TabletDemo/ConfigurableTableViewCell.swift @@ -29,6 +29,6 @@ class ConfigurableTableViewCell: UITableViewCell, ConfigurableCell { @IBAction func buttonClicked(sender: UIButton) { - Action(key: kConfigurableTableViewCellButtonClickedAction, sender: self).perform() + Action(key: kConfigurableTableViewCellButtonClickedAction, sender: self).invoke() } } \ No newline at end of file diff --git a/TabletDemo/TabletDemo/CustomTableActions.swift b/TabletDemo/TabletDemo/CustomTableActions.swift index c586a75..5466099 100644 --- a/TabletDemo/TabletDemo/CustomTableActions.swift +++ b/TabletDemo/TabletDemo/CustomTableActions.swift @@ -15,6 +15,6 @@ extension TableDirector { public func tableView(tableView: UITableView, didEndDisplayingCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { - performAction(.custom(kTableDirectorDidEndDisplayingCell), cell: cell, indexPath: indexPath) + invokeAction(.custom(kTableDirectorDidEndDisplayingCell), cell: cell, indexPath: indexPath) } } \ No newline at end of file