RxSwift方法将UITextView的文本映射并绑定到自定义对象的文本字段?

fin*_*elp 7 swift rx-swift

我知道我可以执行以下操作将更改映射到自定义对象的Notes'文本字段到UITextView.

self.notesViewModel.currentNote()
           .map { $0.text }
           .bindTo(self.notesTextView.rx_text)
Run Code Online (Sandbox Code Playgroud)

如何使用相同的模式进行反向操作?该模式是notesTextView.rx_text,将其映射到当前音符的文本.我知道如何做以下感觉非RxSwift-y:

_ = notesTextView.rx_text.subscribeNext { someText in
    self.notesViewModel.currentNote().value.text = someText
}
Run Code Online (Sandbox Code Playgroud)

IOW,似乎我应该能够获取UITextView(aka notesTextView),映射并将更改绑定到当前注释中.当前注释返回一个带有带有文本字符串字段的注释的变量.

bon*_*oJR 11

您可以使用<->双向绑定运算符.

在RxSwift repo中有一个很好的例子,这是一个用法示例:

// bind UI values to variables
usernameOutlet.rx_text <-> username
passwordOutlet.rx_text <-> password
repeatedPasswordOutlet.rx_text <-> repeatedPassword
Run Code Online (Sandbox Code Playgroud)