Created
February 28, 2017 06:39
-
-
Save TheAdamBorek/5c343353bcd70b0a4b3956fa83408ae6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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