Skip to content

Instantly share code, notes, and snippets.

@vaderdan
Last active December 25, 2018 17:12
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 vaderdan/4ef62152f62d7c8b82fd4dd09982899e to your computer and use it in GitHub Desktop.
Save vaderdan/4ef62152f62d7c8b82fd4dd09982899e to your computer and use it in GitHub Desktop.
// Two way binding operator between control property and relay, that's all it takes.
infix operator <-> : DefaultPrecedence
func <-> <T>(property: ControlProperty<T>, relay: BehaviorRelay<T>) -> Disposable {
let bindToUIDisposable = relay.bind(to: property)
let bindToRelay = property
.subscribe(onNext: { n in
relay.accept(n)
}, onCompleted: {
bindToUIDisposable.dispose()
})
return Disposables.create(bindToUIDisposable, bindToRelay)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment