每当ReactiveCocoa 5中的UITextField文本属性发生更改时,如何获取信号

Mar*_*uro 9 uitextfield reactive-cocoa swift reactive-cocoa-5 reactive-swift

如何从用户启动和以编程方式更改UITextField text属性获得信号?通过continuousTextValues仅在用户启动更改时使用报告信号.如果以textField.text编程方式设置,则不会触发信号.

这就是我使用的方式continuousTextValues:

textField.reactive.continuousTextValues.observeValues { value in
    print("Value: \(value)")
}
Run Code Online (Sandbox Code Playgroud)

如果我text手动设置它不会被触发:

textField.text = "Test"
Run Code Online (Sandbox Code Playgroud)

小智 5

continuousTextValues仅当用户使用键盘输入时才会触发信号。您可以尝试以下操作:

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"
Run Code Online (Sandbox Code Playgroud)