TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Jan 2017 |
SwiftSwift Version | 3.0 |
SPMSupports SPM | ✗ |
Maintained by Fernando Ortiz.
DequeuableRegistrable is a simple set of protocol extensions that allow registering and dequeuing cells and footers/headers (either from UITableView or UICollectionView) without using unsafe strings or explicit casting.
To run the example project, clone the repo, and run pod install
from the Example directory first.
DequeuableRegistrable is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "DequeuableRegistrable", :git => "https://github.com/fmo91/DequeuableRegistrable/"
DequeuableRegistrable turns registering from this:
tableView.register(UINib(nibName: "DogCell", bundle: nil), forCellReuseIdentifier: "DogCell")
to this
DogCell.register(in: tableView)
and turns dequeuing from this:
let cell = tableView.dequeueReusableCell(withIdentifier: "DogCell") as! DogCell
to this:
let cell = DogCell.dequeue(from: tableView)
// cell is DogCell, not UITableViewCell. It's already casted.
at the only cost of doing this:
extension DogCell: Registrable, Dequeuable {}
DequeuableRegistrable consists in three simple protocols:
Identifiable
: It allows to identify any kind of object by providing a key string. In case of cells, that string is the reusable identifier.Dequeuable
: Inherits from Identifiable. It allows to dequeue cells from UICollectionView or UITableView using the reusable identifier provided by Identifiable protocol.Registrable
: Inherits from Identifiable. It allows to register cells in UICollectionView or UITableView using the reusable identifier provided by Identifiable protocol, and a nib object that Registrable protocol requires.All of these protocols have extensions that returns defaults values that match the class name. So, for example, if you have a ABCCell
class, then its default reusable identifier would be "ABCCell"
, and its UINib
would be UINib(nibName: "ABCCell")
Fernando Ortiz, [email protected]
DequeuableRegistrable is available under the MIT license. See the LICENSE file for more info.