Swift Dismiss UITextView Keyboard

You have to set the textview.delegate to self and use the shouldChangeTextInRange function to resign on pressing return.

func textView(textView: UITextView, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool {
    if text == "\n"  // Recognizes enter key in keyboard
    {
        textView.resignFirstResponder()
        return false
    }
    return true
}

swift 3

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