Skip to content

Latest commit

 

History

History
41 lines (27 loc) · 977 Bytes

README.md

File metadata and controls

41 lines (27 loc) · 977 Bytes

Reusable

Swift

Provides a more type-safe way of registering and dequeuing table/collection view cells.

Usage

Have your table or collection view cell class conform to Reusable.

class ExampleCell: UITableViewCell, Reusable {

    func configure(...) { ... }
}

If your cell uses a NIB for its UI, then conform to NibReusable.

class ExampleCell: UITableViewCell, NibReusable {

    func configure(...) { ... }
}

Use the register extension methods to register your cell classes with your table/collection view.

ExampleCell.registerReusableCell(for: tableView)

Use the dequeue extension methods to dequeue cells in your data source.

let cell = ExampleCell.dequeueReusableCell(for: tableView, at: indexPath)
cell.configure(...)

return cell

The cell instance is already of the correct type so there's no need to cast it in your data source.