Skip to content

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

License

Notifications You must be signed in to change notification settings

jerrodputman/Reusable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.