CocoaPods trunk is moving to be read-only. Read more on the blog, there are 19 months to go.
TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Oct 2017 |
SwiftSwift Version | 4.0 |
SPMSupports SPM | ✗ |
Maintained by Rob Nash.
Dequable allows you to write strongly typed let constants for your dequable UI components and limits the need for string based cell identifiers.
If you don't use interface builder, then you will not need to declare any cell identifiers.
Declare conformance.
class TableViewCell: UITableViewCell, DequeableComponentIdentifiable {}
class TableView: UITableView, DequeableTableView {}
Register cells if you need to.
class TableView: UITableView, DequeableTableView {
override init(frame: CGRect, style: UITableViewStyle) {
super.init(frame: frame, style: style)
register(cellType: TableViewCell.self, hasNib: false)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}
Now you can dequee strongly typed let constants.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: TableViewCell = (tableView as! DequeableTableView).dequeue(indexPath)
return cell
}
You may want to use the awesome Require framework to lock down your types.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let dequeableTableView: DequeableTableView = (tableView as? DequeableTableView).require(hint: "TableView must conform to DequeableTableView")
let cell: TableViewCell = dequeableTableView.dequeue(indexPath)
return cell
}
If you use interface builder then you will need to specify a cell identifier there. The cell identifier should be "Filename"
+ "ID"
. In this example it would be "TableViewCellID"
.
It is asssumed your interface builder file is in the same bundle. So in this example, if we created an interface builder file for TableViewCell, we would include it in the same bundle as the TableViewCell.swift file.
If you like this and you want to buy me a drink, use bitcoin.
Bitcoin Address: 15Gj4DBTzSujnJrfRZ6ivrR9kDnWXNPvNQ