Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

301
Visualizações
How to implement shouldChangeTextIn the RxSwift way

Is there a way to implement the shouldChangeTextIn UITextView's delegate method in RxSwift way? My goal is to limit the text input of the user. I just have this:

    self.textView.rx.text
        .orEmpty
        .scan("") { (previous, new) -> String in
            return new.count > 254 ? previous : new
        }
        .bind(to: self.viewModel.notes)
        .disposed(by: self.disposeBag)

This is for data, but I don't know how to prevent the further input after 254 count.

I also found RxTextViewDelegateProxy but I'm not sure too how to use it.

let rxTVDelegateProxy = RxTextViewDelegateProxy(textView: self.textView)
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Try this:

       textView.rx.text.orEmpty
        .scan("") { (previous, new) -> String in

            return new.count < 254 ? new : previous ?? String(new.prefix(254))
        }
        .bind(to: textView.rx.text)
        .disposed(by: disposeBag)
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda