How do you get a signal from both user-initiated and programmatically made changes to UITextField
text
property? By using continuousTextValues
only reports a signal when the user has initiated the change. If you set textField.text
programmatically, the signal doesn't fire.
This is how I'm using continuousTextValues
:
textField.reactive.continuousTextValues.observeValues { value in
print("Value: \(value)")
}
It doesn't get triggered if I set text
manually:
textField.text = "Test"
The signal continuousTextValues
will only be triggered while user input using the keyboard.You could try this:
var characters = MutableProperty("")
tf.reactive.text <~ characters
tf.reactive.continuousTextValues.observeValues { [weak characters = characters] (text) in
characters?.value = text!
}
tf.reactive.textValues.observeValues { [weak characters = characters] (text) in
characters?.value = text!
}
characters.producer.skip(while: { $0.isEmpty }).startWithValues { (text) in
log.debug("text = \(text)")
}
characters.value = "shaw"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With