7

I know I can do the following to map changes to a custom object's Notes' text field to a UITextView.

self.notesViewModel.currentNote()
           .map { $0.text }
           .bindTo(self.notesTextView.rx_text)

How can I do the reverse using the same kind of pattern? The pattern is notesTextView.rx_text, map it to the current note's text. I know how to do the following which feels non-RxSwift-y:

_ = notesTextView.rx_text.subscribeNext { someText in
    self.notesViewModel.currentNote().value.text = someText
}

IOW, it seems like I should be able to take the UITextView (aka notesTextView), map, and bind changes into the current note. Current note returns a Variable with a Note having a text String field.

4

2 に答える 2

11

<->双方向バインディング演算子を使用できます。

RxSwift repoに良い例があります。使用例は次のとおりです。

// bind UI values to variables
usernameOutlet.rx_text <-> username
passwordOutlet.rx_text <-> password
repeatedPasswordOutlet.rx_text <-> repeatedPassword
于 2015-11-28T11:33:15.110 に答える