- Container helps work with information and can handle data
- Data Source abstraction, which include container and displays data from container
used with arrays data
func insert(object: ResultType, at indexPath: IndexPath) throws { }
func remove(at indexPath: IndexPath) throws { }
func replace(object: ResultType, at indexPath: IndexPath, reloadAction: Bool = false) throws { }
func removeAll() { }
used with data from fetch result controller
var fetchedObjects: [ResultType]
func object(at indexPath: IndexPath) -> ResultType? { }
func search(_ block:(IndexPath, ResultType) -> Bool) { }
func indexPath(for object: ResultType) -> IndexPath? { }
func filterData(by searchText: String?) { }
func numberOfItems(in section: Int) -> Int? { }
func object(at indexPath: IndexPath) -> T? { }
func dataSource(_ dataSource: DataSourceProtocol, cellIdentifierFor object: ObjectType, at indexPath: IndexPath) -> String?
func dataSource(_ dataSource: DataSourceProtocol, accessoryTypeFor object: ObjectType, at indexPath: IndexPath) -> UITableViewCell.AccessoryType?
func dataSource(_ dataSource: DataSourceProtocol, didSelect object: ObjectType, at indexPath: IndexPath)
func dataSource(_ dataSource: DataSourceProtocol, didDeselect object: ObjectType, at indexPath: IndexPath?)
func dataSource(_ dataSource: DataSourceProtocol, didSelect object: ObjectType) { }
all DataSources have property noDataView which is show, when there are no data in containers
View Controller properties
var container: FRCDataSourceContainer<ClassType>?
@IBOutlet weak var tableView: UITableView! {
didSet {
dataSource.tableView = tableView
tableView.registerCellNibForDefaultIdentifier(TableViewCell.self)
dataSource.noDataView = NoDataView()
}
private lazy var dataSource: TableViewDataSource<ClassType> = {
let dataSource = TableViewDataSource<ClassType>(delegate: AnyTableViewDataSourceDelegate(self))
dataSource.cellIdentifier = TableViewCell.defaultReuseIdentifier
return dataSource
}()
View Controller methods
extension ViewController: TableViewDataSourceDelegate {
typealias ObjectType = ClassType
func dataSource(_ dataSource: DataSourceProtocol, didSelect object: ClassType, at indexPath: IndexPath) { }
}