Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DataSourceKit/CellBinder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public struct CellBinder {
self.reuseIdentifier = reuseIdentifier
self.configureCell = { cell in
guard let cell = cell as? Cell else {
fatalError("Could not cast UICollectionView cell to \(Cell.self)")
fatalError("Could not cast cell to \(Cell.self)")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch 👍

}

configureCell(cell)
Expand Down
18 changes: 14 additions & 4 deletions DataSourceKit/CollectionViewDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,25 @@
import UIKit

public class CollectionViewDataSource<CellDeclaration>: NSObject, UICollectionViewDataSource {

// MARK: Public Properties
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I think these kinds of comments are redundant.


public typealias Configurator = (CellDeclaration) -> CellBinder
public var cellDeclarations = [] as [CellDeclaration]


// MARK: Private Properties

private var registeredReuseIdentifiers = [] as [String]
private let binderFromDeclaration: (CellDeclaration) -> CellBinder

public init(binderFromDeclaration: @escaping (CellDeclaration) -> CellBinder) {
private let binderFromDeclaration: Configurator

// MARK: Init

public init(binderFromDeclaration: @escaping Configurator) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(CellDeclaration) -> CellBinder is short enough and clearer than Configurator.

self.binderFromDeclaration = binderFromDeclaration
super.init()
}

// MARK: UICollectionViewDataSource

public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return cellDeclarations.count
Expand Down
20 changes: 16 additions & 4 deletions DataSourceKit/TableViewDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,25 @@
import UIKit

public class TableViewDataSource<CellDeclaration>: NSObject, UITableViewDataSource {

// MARK: Public Properties

public typealias Configurator = (CellDeclaration) -> CellBinder
public var cellDeclarations = [] as [CellDeclaration]


// MARK: Private Properties

private var registeredReuseIdentifiers = [] as [String]
private let binderFromDeclaration: (CellDeclaration) -> CellBinder

public init(binderFromDeclaration: @escaping (CellDeclaration) -> CellBinder) {
private let binderFromDeclaration: Configurator

// MARK: Init

public init(binderFromDeclaration: @escaping Configurator) {
self.binderFromDeclaration = binderFromDeclaration
super.init()
}

// MARK: UITableViewDataSource

public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return cellDeclarations.count
Expand All @@ -36,8 +46,10 @@ public class TableViewDataSource<CellDeclaration>: NSObject, UITableViewDataSour
}
registeredReuseIdentifiers.append(cellBinder.reuseIdentifier)
}

let cell = tableView.dequeueReusableCell(withIdentifier: cellBinder.reuseIdentifier, for: indexPath)
cellBinder.configureCell(cell)

return cell
}
}
2 changes: 1 addition & 1 deletion DataSourceKitTests/Example/CTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import DataSourceKit
class CTableViewCell: UITableViewCell {
var idLabel = UILabel(frame: .zero)

override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is applied in #13, so please update this branch. Sorry for my late response 🙇

super.init(style: style, reuseIdentifier: reuseIdentifier)
contentView.addSubview(idLabel)
idLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor)
Expand Down