Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. import RxSwift
  2. import RxRelay
  3. // 1
  4. import RxDataSources
  5.  
  6. class TodoListViewModel {
  7. private let addButtonPublishRelay = PublishRelay<Void>()
  8. // 2
  9. private let todoListCellViewModelsBehaviorRelay = BehaviorRelay<[TodoListCellViewModel]>(value: [])
  10.  
  11. var addButtonObserver: AnyObserver<Void> {
  12. return AnyObserver {
  13. guard let element = $0.element else { return }
  14. self.addButtonPublishRelay.accept(element)
  15. }
  16. }
  17.  
  18. // 3
  19. let dataSource = RxTableViewSectionedReloadDataSource<TodoListSection>(configureCell: {dataSource, tableView, indexPath, item in
  20. guard let cell = tableView.dequeueReusableCell(withIdentifier: "TodoListTableViewCell") as? TodoListTableViewCell else { return UITableViewCell() }
  21. cell.bind(to: item)
  22.  
  23. return cell
  24. })
  25.  
  26. // 4
  27. init() {
  28. dataSource.titleForHeaderInSection = { dataSource, index in
  29. return dataSource.sectionModels[index].header
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement