7

I have

@IBOutlet weak var messageTextView: UITextView

and I want that when there is a change inside the text then print to console: blabla.

I tried to add the following function, but when I change the text nothing happens:

func textViewDidChange(_ textView: UITextView) {
    switch (textView) {
        case messageTextView: print("blabla")
        default: break
    }
}
Jerry Stratton
  • 3,287
  • 1
  • 22
  • 30
trycatch
  • 135
  • 1
  • 8
  • 4
    Possible duplicate of [How do I use textViewDidChange?](https://stackoverflow.com/questions/17529018/how-do-i-use-textviewdidchange) – Kamran Sep 10 '18 at 13:25
  • @Kamran IMO, the question you linked is of worse quality than this one (no code provided in the one you linked), I'd recommend marking that question as a dupe of this one instead. – jrh Jul 08 '19 at 00:01
  • @jrh I linked that question to read the answer that has a fix for this question. – Kamran Jul 08 '19 at 04:43

1 Answers1

10

You need to set the delegate inside viewDidLoad

textView.delegate = self

//

class ViewController: UIViewController , UITextViewDelegate  {
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87