-
-
Save Busta117/9dd42e66d09874c4b695c92bde983496 to your computer and use it in GitHub Desktop.
Bidirectional bind RxSwift, swift 3
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
infix operator <~> : AssignmentPrecedence | |
//Bidirectional bind RxSwift, swift 3 | |
public func <~> <E,C: ControlPropertyType>(property: C, variable: Variable<E>) -> Disposable where C.E == E? { | |
let bindToUIDisposable = variable.asObservable() | |
.bindTo(property) | |
let bindToVariable = property | |
.subscribe(onNext: { n in | |
if let n = n{ | |
variable.value = n | |
} | |
}, onCompleted: { | |
bindToUIDisposable.dispose() | |
}) | |
return Disposables.create([bindToUIDisposable, bindToVariable]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment