Skip to content

Instantly share code, notes, and snippets.

@alfian0
Last active July 4, 2018 05:11
Show Gist options
  • Save alfian0/ad5f98b3d66db9ef533f6755dbdb8854 to your computer and use it in GitHub Desktop.
Save alfian0/ad5f98b3d66db9ef533f6755dbdb8854 to your computer and use it in GitHub Desktop.
final class ViewController: UITableViewController {
var viewModel: ViewModel!
let disposeBag = DisposeBag()
override func viewDidLoad() {
super.viewDidLoad()
let input = viewModel.Input()
let output = viewModel.transform(input: input)
output.bind(to: tableView.rx.items(cellIdentifier: “Cell")) { row, item, cell in
cell.textLabel!?text = "\(item) @ row \(row)"
}
.disposed(by: disposeBag)
}
}
final class ViewModel: ViewModelType {
struct Input {
let text: Driver<String>
}
struct Output {
let items: Driver<[String]>
}
func transform(input: Input) -> Output {
let items = input
.orEmpty
.throttle(0.3, scheduler: Mainscheduler.instance)
.distinctUntilChanged()
.map{ ["1", "2", "3"] }
return Output(items: items)
}
}
protocol ViewModelType {
associatedtype Input
associatedtype Output
func transform(input: Input) -> Output
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment