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

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

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

Best,

Show your support

Clapping shows how much you appreciated SDN SPR’s story.