Best way to dismiss Keyboard in a View Controller iOS (Swift)
Kaushal Elsewhere
1.4K15

With Swift 3.0 you can do something like:

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.view.endEditing(true)
}

in your view controller you wish to have this behavior on. It also works “through” other views, such as tapping on a label that’s in your view.