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

extension UIViewController {
 internal func hideKeyboardOnTap(){
 let tap = UITapGestureRecognizer(target: self, action: #selector(self.hideKeyboard))
 tap.cancelsTouchesInView = false
 @objc private func hideKeyboard(){

just call hideKeyboardOnTap() in any viewController viewDidLoad() function.


Like what you read? Give SDN SPR a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.