SHARE
TWEET

Untitled

a guest Oct 18th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top