'UIKeyCommand action not being called in swift

I have a UITextView and I type a text and then when I press shift+enter or option+enter, keyTapped() is not getting called. This is my code:

override public var keyCommands: [UIKeyCommand]? {
    return [
      UIKeyCommand(title: "New line",
                           action: #selector(keyTapped(_:)),
                           input:"\r",
                           modifierFlags: .alternate),
      UIKeyCommand(title: "New line",
                           action: #selector(keyTapped(_:)),
                           input: "\r",
                           modifierFlags: .shift)
    ]
  }

This is my action function:

@objc func keyTapped(_ sender: UIKeyCommand) {
    _handleTextViewDidChange(textView)
 }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source