How to hide keyboard when you press keyboard return button in UITextView

Use following code for hide keyboard when you press UITextview keyboard's return button in swift 3 or later


 func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
        if (text == "\n") {
            textView.resignFirstResponder()
            return false
            // or true, whetever you's like
        }
        return true
    }