Skip to content

Instantly share code, notes, and snippets.

@TheAdamBorek
Created February 28, 2017 06:39
Show Gist options
  • Save TheAdamBorek/5c343353bcd70b0a4b3956fa83408ae6 to your computer and use it in GitHub Desktop.
Save TheAdamBorek/5c343353bcd70b0a4b3956fa83408ae6 to your computer and use it in GitHub Desktop.
import Foundation
import RxSwift
import RxSwiftExt
import RxCocoa
extension Variable {
func bidirectionalBind(with controlProperty: ControlProperty<Element>) -> Disposable {
let bindingToControl = self
.asDriver()
.drive(controlProperty)
let bindingToVariable = controlProperty
.skipUntil(self.asObservable())
.bindTo(self)
return Disposables.create(bindingToControl, bindingToVariable)
}
func bidirectionalBind(with controlProperty: ControlProperty<Optional<Element>>) -> Disposable {
let bindingToControl = self
.asDriver()
.drive(controlProperty)
let bindingToVariable = controlProperty
.skipUntil(self.asObservable())
.unwrap()
.bindTo(self)
return Disposables.create(bindingToControl, bindingToVariable)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment