Dismissing the keyboard (the simple way)

As UIViewController inherits from UIResponder, it supports touch events.

class ConversionViewController: UIViewController {
...
  override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    view.endEditing(true)
  }
}
1 Like

This is a nice alternate solution. For whatever reason, I was crashing and receiving an error “textfield.resignfirstresponder() unexpectedly found nil when unwrapping optional value” and I couldn’t exactly figure out what was causing it.

It is likely that textField in ViewController is not connected to the UITextField in storyboard.

1 Like