Chapter 26: Adding Polish :: Page 599 Deactivate the Keyboard

That version resigns in both branches of the If…Else, so it always resigns. The flicker is a new one coming back if you are in the text box.
I checked, and some of the Apple apps only resign when a different row is tapped, not for taps that aren’t in a row at all. So you can do it either way, according to taste. But it should be the same in all three versions in the book, whichever way it goes. It is all too easy to think something is logically equivalent when it isn’t for a particular case.

Here is my favorite version, because it comes closest to saying what you really mean:

if indexPath == nil || indexPath != IndexPath(row: 0, section: 0) {
  descriptionTextView.resignFirstResponder()
}
1 Like