Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import RxSwift
- import RxRelay
- // 1
- import RxDataSources
- class TodoListViewModel {
- private let addButtonPublishRelay = PublishRelay<Void>()
- // 2
- private let todoListCellViewModelsBehaviorRelay = BehaviorRelay<[TodoListCellViewModel]>(value: [])
- var addButtonObserver: AnyObserver<Void> {
- return AnyObserver {
- guard let element = $0.element else { return }
- self.addButtonPublishRelay.accept(element)
- }
- }
- // 3
- let dataSource = RxTableViewSectionedReloadDataSource<TodoListSection>(configureCell: {dataSource, tableView, indexPath, item in
- guard let cell = tableView.dequeueReusableCell(withIdentifier: "TodoListTableViewCell") as? TodoListTableViewCell else { return UITableViewCell() }
- cell.bind(to: item)
- return cell
- })
- // 4
- init() {
- dataSource.titleForHeaderInSection = { dataSource, index in
- return dataSource.sectionModels[index].header
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement