35 lines
749 B
Swift
35 lines
749 B
Swift
//
|
|
// Operators.swift
|
|
// RxExample
|
|
//
|
|
// Created by Krunoslav Zaher on 12/6/15.
|
|
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
#if !RX_NO_MODULE
|
|
import RxSwift
|
|
import RxCocoa
|
|
#endif
|
|
|
|
// Two way binding operator between control property and variable, that's all it takes {
|
|
|
|
infix operator <-> {
|
|
}
|
|
|
|
func <-> <T>(property: ControlProperty<T>, variable: Variable<T>) -> Disposable {
|
|
let bindToUIDisposable = variable
|
|
.bindTo(property)
|
|
let bindToVariable = property
|
|
.subscribe(onNext: { n in
|
|
variable.value = n
|
|
}, onCompleted: {
|
|
bindToUIDisposable.dispose()
|
|
})
|
|
|
|
return StableCompositeDisposable.create(bindToUIDisposable, bindToVariable)
|
|
}
|
|
|
|
// }
|
|
|