class ViewController: UIViewController, UITextFieldDelegate {
// as long as user touch the app, keyboard will hide
override func touchesBegan(_ touches: Set<UITouch>, with event:UIEvent?) {
self.view.endEditing(true)
}
// when user touch "return",keyboard will hide
func textFieldShouldReturn(_ textField:UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
}