Skip to content

Instantly share code, notes, and snippets.

@Busta117
Created November 21, 2016 21:25
Show Gist options
  • Save Busta117/9dd42e66d09874c4b695c92bde983496 to your computer and use it in GitHub Desktop.
Save Busta117/9dd42e66d09874c4b695c92bde983496 to your computer and use it in GitHub Desktop.
Bidirectional bind RxSwift, swift 3
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