Skip to content

Instantly share code, notes, and snippets.

@stinger
Created January 2, 2017 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stinger/d9e7779b5728cffe6c9f6c58e841e500 to your computer and use it in GitHub Desktop.
Save stinger/d9e7779b5728cffe6c9f6c58e841e500 to your computer and use it in GitHub Desktop.
RxSwift MVVM view sinks
class MyCustomView : UIView {
var sink : AnyObserver<SomeComplexStructure> {
return AnyObserver { [weak self] event in
switch event {
case .next(let data):
self?.something.text = data.property.text
break
case .error(let error):
self?.backgroundColor = .red
case .completed:
self.alpha = 0
}
}
}
}
class ViewController {
let myCustomView : MyCustomView
override func viewDidLoad(){
super.viewDidLoad()
viewModel.dataStream
.bindTo(myCustomView.sink)
.addTo(disposeBag)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment