RxSwift Events of UITextView

Viewed 4514

When I implement UITextFieldDelegate through RxSwift, I do this:

self.textField_AddressType.rx.controlEvent(.editingDidBegin).subscribe { _ in
    // Code here...
}.disposed(by: self.disposeBag)

But when I apply it to UITextView,

self.textView.rx.controlEvent(.editingDidBegin).subscribe { _ in
   // Code here...
}.disposed(by: self.disposeBag)

I get an error:

'UITextView' is not a subtype of 'UIControl'

I couldn't find anything about this issue, is there another way to implement UITextViewDelegate in RxSwift?

2 Answers
textView.rx.didBeginEditing.subscribe(onNext: { n in
  value = n
}, onCompleted: {
  completed = true
})

You can try this.

You can map event and create Observable string like this

self.tfUserName.rx.controlEvent(UIControlEvents.editingDidEnd)
        .map { self.tfUserName.text }
        .filter { $0 != nil }
        .map { $0! }
        .subscribe(onNext: { (text) in
            // Code here...
        }).disposed(by: self.disposeBag)
Related