EasyList is a UITableView subclass, that will help you create type-safe lists, with less code, easier to read and maintain.
As you probably know, using UITableView forces you to implement delegate pattern, switch statements (In case of different cell types) force casting (UITableViewCell to your custom cell type), and redundant code as 'cellIdentifier'.
EasyList is a new way of dealing with simple to complex table views; it wrapped logic for you, so you have a less boilerplate redundant code.
ListTypeStaticCellHeight, Supports multiple cell types, static height
let cellConfiguration = CellConfiguration { (cell, indexPath) -> YourCustomCell in
cell.setText(self.dataSource[indexPath.row])
return cell
}
let listType = ListTypeStaticCellHeight.init(
cellConfiguration: { indexPath -> CellConfigurationType in
return cellConfiguration
}, dataSourceCount: { () -> Int in
return self.dataSource.count
}, rowHeight: { indexPath -> CGFloat in
return 50
}) { (selectedCell, selectedIndexPath) in
///Did select cell
}
self.easyList = EasyList.init(listType)
ListTypeAutoSizingCells, Supports multiple cell types, dynamic cell height
let cellConfiguration = CellConfiguration { (cell, indexPath) -> YourCustomCell in
cell.setText(self.dataSource[indexPath.row])
return cell
}
let cellConfiguration2 = CellConfiguration { (cell, indexPath) -> YourCustomCellWithDinamicSize in
cell.setText(self.dataSource[indexPath.row])
return cell
}
let listType = ListTypeAutoSizingCells.init(
cellConfiguration: { indexPath -> CellConfigurationType in
if (indexPath.row == 5) {
return cellConfiguration2
}
return cellConfiguration
}, dataSourceCount: { () -> Int in
return self.dataSource.count
}, estimatedRowsHeight: 100) { (selectedCell, selectedIndexPath) in
///Did select cell
}
self.easyList = EasyList.init(listType)
CellConfiguration block is used to define different cell types. Set Its return type to your custom cell, and set Its params. After creating the amount of cell configuration blocks you need, choose your ListType:
- ListTypeAutoSizingCells for auto sizing cells
- ListTypeStaticCellHeight static cell sizes
Create it, pass CellConfiguration for index path, and the rest of the params (Should be autocompleted)
Reloading data on change is the same as using UITableView (Because it is, in fact, a UITableView) call: reloadData()
You are ready to go! (:
EasyList is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'EasyList'
- Download and drop
/EasyList
folder in your project. - Congratulations!
Matan made this with ❤️.