Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RxSwift Events of UITextView

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?

like image 746
Glenn Posadas Avatar asked Sep 18 '18 03:09

Glenn Posadas


2 Answers

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

You can try this.

like image 60
Gary Lip Avatar answered Nov 19 '22 05:11

Gary Lip


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)
like image 20
Burak Öner Avatar answered Nov 19 '22 04:11

Burak Öner