This is how I currently implement this behavior, I'm pretty new to RAC, so grab it with salt.
I use ReactiveCocoa 4.1.0 & Rex 0.10.0
ViewModel
- Set
MutableProperty
tooriginalText
Mutable properties producer
, .
originalText.producer.startWithNext
1 , ViewModel
let originalText: MutableProperty<String> = MutableProperty("")
func observeTextField(){
originalText.producer.startWithNext { (str) in
self.model.originalText = str
}
}
Rex . ignoreError
Rex .
SignalProducer
SignalProducer<T, ErrorType>
, ErrorType
MutableProperty<String>
.
- .
- ViewModel
MutableProperty
ViewModel.observeTextField
3
infix <~
ViewModel MutableProperty
import Rex
...
let textFieldProducer = (originalTextField.rac_textSignal()
.toSignalProducer()
.map {text in text as! String}
.ignoreError())!
viewModelInstance.originalText <~ textFieldProducer
, .
user2038460