Skip to content

Commit

Permalink
Merge branch 'master' into xcode9.3
Browse files Browse the repository at this point in the history
  • Loading branch information
srdanrasic committed Apr 14, 2018
2 parents aaf141a + 11c6657 commit e730789
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
12 changes: 10 additions & 2 deletions Sources/Bond/UIKit/UICollectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@
/// A type used by the collection view bindings that provides binding options and actions.
open class CollectionViewBinder<DataSource: DataSourceProtocol> {

open let createCell: (DataSource, IndexPath, UICollectionView) -> UICollectionViewCell
open let createCell: ((DataSource, IndexPath, UICollectionView) -> UICollectionViewCell)?

public init() {
createCell = nil
}

/// - parameter createCell: A closure that creates cell for a given collection view and configures it with the given data source at the given index path.
public init(_ createCell: @escaping (DataSource, IndexPath, UICollectionView) -> UICollectionViewCell) {
Expand All @@ -69,7 +73,11 @@

/// - returns: A cell for the given collection view configured with the given data source at the given index path.
open func cellForRow(at indexPath: IndexPath, collectionView: UICollectionView, dataSource: DataSource) -> UICollectionViewCell {
return createCell(dataSource, indexPath, collectionView)
if let createCell = createCell {
return createCell(dataSource, indexPath, collectionView)
} else {
fatalError("Subclass of CollectionViewBinder should override and implement cellForRow(at:collectionView:dataSource:) method. Do not call super.")
}
}
}

Expand Down
12 changes: 10 additions & 2 deletions Sources/Bond/UIKit/UITableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@

open var rowAnimation: UITableViewRowAnimation = .automatic

open let createCell: (DataSource, IndexPath, UITableView) -> UITableViewCell
open let createCell: ((DataSource, IndexPath, UITableView) -> UITableViewCell)?

public init() {
createCell = nil
}

/// - parameter createCell: A closure that creates cell for a given table view and configures it with the given data source at the given index path.
public init(_ createCell: @escaping (DataSource, IndexPath, UITableView) -> UITableViewCell) {
Expand All @@ -72,7 +76,11 @@

/// - returns: A cell for the given table view configured with the given data source at the given index path.
open func cellForRow(at indexPath: IndexPath, tableView: UITableView, dataSource: DataSource) -> UITableViewCell {
return createCell(dataSource, indexPath, tableView)
if let createCell = createCell {
return createCell(dataSource, indexPath, tableView)
} else {
fatalError("Subclass of TableViewBinder should override and implement cellForRow(at:tableView:dataSource:) method. Do not call super.")
}
}

/// Applies the given data source event to the table view.
Expand Down

0 comments on commit e730789

Please sign in to comment.