6

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,057
  • 1
  • 21
  • 27
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  {
Sh_Khan
  • 93,445
  • 7
  • 57
  • 76