稀土 2018-01-28
func racsTest() { textField.reactive.continuousTextValues.observeValues { (text) in print("值为:\(text ?? "")") } }
结果:
方法一:
textField.reactive.continuousTextValues.map { (text) -> Int in return (text?.count)!//!.characters.count }.observeValues { (count) in print("数值为:\(count)") }
输入: Hello123
结果为:
方法二:
1 let (signal, observer) = Signal<String, NoError>.pipe() 2 signal.map { (string) -> Int in 3 return string.lengthOfBytes(using: .utf8) 4 }.observeValues { (length) in 5 print("长度length: \(length)") 6 } 7 8 observer.send(value: "123456") 9 10 observer.send(value: "some")
结果为:
filter函数可以按照之前预设的条件过滤掉不满足的值