Skip to content

Commit 6c11676

Browse files
committed
fixed for latest Swift 3 syntax
1 parent 5cf3ea5 commit 6c11676

5 files changed

+22
-22
lines changed

Diff for: DataSource/DataSource.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public struct Section<T>: SectionType {
7878
public let footer: String?
7979

8080
/// Closure which returns a row given its index
81-
public let rowCreatorClosure: ((rowIndex: Int) -> Row<T>)?
81+
public let rowCreatorClosure: ((_ rowIndex: Int) -> Row<T>)?
8282

8383
/// Closure which returns the total number of rows
8484
public let rowCountClosure: (() -> Int)?
@@ -107,7 +107,7 @@ public struct Section<T>: SectionType {
107107
}
108108

109109
/// Initializes a section with a row creator closure
110-
public init(title: String? = nil, footer: String? = nil, rowCountClosure: (() -> Int), rowCreatorClosure: (rowIndex: Int) -> Row<T>) {
110+
public init(title: String? = nil, footer: String? = nil, rowCountClosure: @escaping (() -> Int), rowCreatorClosure: @escaping (Int) -> Row<T>) {
111111
self.rows = []
112112
self.title = title
113113
self.footer = footer
@@ -117,7 +117,7 @@ public struct Section<T>: SectionType {
117117

118118
public func rowAtIndex(_ index: Int) -> Row<T> {
119119
if let creator = rowCreatorClosure {
120-
return creator(rowIndex: index)
120+
return creator(index)
121121
} else {
122122
return rows[index]
123123
}

Diff for: DataSource/TableViewCellConfigurator.swift

+12-11
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,42 @@ public protocol TableViewCellConfiguratorType {
1515
var rowIdentifier: String { get }
1616
var cellIdentifier: String { get }
1717

18-
func configureRow(_ row: RowType, cell: UITableViewCell, indexPath: IndexPath)
18+
func configure(row: RowType, cell: UITableViewCell, indexPath: IndexPath)
1919
}
2020

2121
// MARK: - TableViewCellConfigurator
2222

2323
public class TableViewCellConfigurator<T, C: UITableViewCell>: TableViewCellConfiguratorType {
24+
2425
/// Row identifier this configurator is responsible for
2526
public var rowIdentifier: String
26-
27+
2728
/// Cell identifier used to dequeue a table view cell
2829
public var cellIdentifier: String
2930

3031
/// Typed configuration closure
31-
var configure: ((T, C, IndexPath) -> Void)?
32+
var closure: ((T, C, IndexPath) -> Void)?
3233

3334
/// Initializes the configurator given row and cell identifiers and a configure closure
34-
public init (rowIdentifier: String, cellIdentifier: String, configure: ((data: T, cell: C, indexPath: IndexPath) -> Void)? = nil) {
35+
public init (rowIdentifier: String, cellIdentifier: String, configure: ((T, C, IndexPath) -> Void)? = nil) {
3536
self.cellIdentifier = cellIdentifier
3637
self.rowIdentifier = rowIdentifier
37-
self.configure = configure
38+
self.closure = configure
3839
}
3940

4041
/// Initializes the configurator using the same identifier for rowIdentifier and cellIdentifier and a configure closure
41-
public convenience init (_ cellIdentifier: String, configure: ((data: T, cell: C, indexPath: IndexPath) -> Void)? = nil) {
42+
public convenience init (_ cellIdentifier: String, configure: ((T, C, IndexPath) -> Void)? = nil) {
4243
self.init(rowIdentifier: cellIdentifier, cellIdentifier: cellIdentifier, configure: configure)
4344
}
44-
45+
4546
/// Takes a row and cell, makes the required casts and calls the configure closure
46-
public func configureRow(_ row: RowType, cell: UITableViewCell, indexPath: IndexPath) {
47-
guard let configure = configure else { return }
47+
public func configure(row: RowType, cell: UITableViewCell, indexPath: IndexPath) {
48+
guard let closure = closure else { return }
4849

4950
if let data = row.anyData as? T, let cell = cell as? C {
50-
configure(data, cell, indexPath)
51+
closure(data, cell, indexPath)
5152
} else {
52-
fatalError("invalid row or cell type (row: \(row.identifier), cell: \(String(cell)))");
53+
fatalError("invalid row or cell type (row: \(row.identifier), cell: \(String(describing: cell)))");
5354
}
5455
}
5556
}

Diff for: DataSource/TableViewDataSource.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class TableViewDataSource: NSObject {
2929
public var configureWithoutAnimations: Bool = true
3030

3131
/// Optional closure which is called after a cell is dequeued, but before it's being configured (e.g. to "reset" a cell)
32-
public var prepareCell: ((UITableViewCell, indexPath: IndexPath) -> Void)?
32+
public var prepareCell: ((UITableViewCell, IndexPath) -> Void)?
3333

3434
/// Registered cell configurators
3535
var configurators = [String: TableViewCellConfiguratorType]()
@@ -86,12 +86,12 @@ extension TableViewDataSource: UITableViewDataSource {
8686
let configure: () -> UITableViewCell = {
8787
if let configurator = self.configuratorForRowIdentifier(row.identifier) {
8888
let cell = tableView.dequeueReusableCell(withIdentifier: configurator.cellIdentifier, for: indexPath)
89-
self.prepareCell?(cell, indexPath: indexPath)
90-
configurator.configureRow(row, cell: cell, indexPath: indexPath)
89+
self.prepareCell?(cell, indexPath)
90+
configurator.configure(row: row, cell: cell, indexPath: indexPath)
9191
return cell
9292
} else {
9393
let cell = tableView.dequeueReusableCell(withIdentifier: row.identifier, for: indexPath)
94-
self.prepareCell?(cell, indexPath: indexPath)
94+
self.prepareCell?(cell, indexPath)
9595
return cell
9696
}
9797
}

Diff for: Example/AppDelegate.swift

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1313

1414
var window: UIWindow?
1515

16-
17-
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
16+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
1817
// Override point for customization after application launch.
1918
return true
2019
}
21-
20+
2221
func applicationWillResignActive(_ application: UIApplication) {
2322
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
2423
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

Diff for: Example/StartViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class StartViewController: UITableViewController {
2525
return cell
2626
}
2727

28-
override func prepare(for segue: UIStoryboardSegue, sender: AnyObject?) {
28+
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
2929
let index = (tableView.indexPathForSelectedRow! as NSIndexPath).row
3030
let viewController = segue.destination as! ExampleTableViewController
3131
viewController.title = titles[index]

0 commit comments

Comments
 (0)