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
letcellConfiguration=CellConfiguration{(cell, indexPath)->YourCustomCellin
cell.setText(self.dataSource[indexPath.row])return cell
}letlistType=ListTypeStaticCellHeight.init(
cellConfiguration:{ indexPath ->CellConfigurationTypeinreturn cellConfiguration
}, dataSourceCount:{()->Intinreturnself.dataSource.count
}, rowHeight:{ indexPath ->CGFloatinreturn50}){(selectedCell, selectedIndexPath)in
///Did select cell
}self.easyList =EasyList.init(listType)ListTypeAutoSizingCells, Supports multiple cell types, dynamic cell height
letcellConfiguration=CellConfiguration{(cell, indexPath)->YourCustomCellin
cell.setText(self.dataSource[indexPath.row])return cell
}letcellConfiguration2=CellConfiguration{(cell, indexPath)->YourCustomCellWithDinamicSizein
cell.setText(self.dataSource[indexPath.row])return cell
}letlistType=ListTypeAutoSizingCells.init(
cellConfiguration:{ indexPath ->CellConfigurationTypeinif(indexPath.row ==5){return cellConfiguration2
}return cellConfiguration }, dataSourceCount:{()->Intinreturnself.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
/EasyListfolder in your project. - Congratulations!
Matan made this with ❤️.
