iOS Apprentice v5.0, Tutorial 3, error in if-statement logic

Hi,

i think there is a little error in the third alternative if-statement on page 117.
The code in the body should not be “return”, but “descriptionTextView.resignFirstResponder()”:

if let indexPath = indexPath, indexPath.section != 0 &&
                                              indexPath.row != 0 {
  description.TextView.resignFirstResponder()
}

Why do you think it is wrong? Notice that we flipped the == to !=, thereby negating the meaning of the if-statement.

Here is the original snippet from the book page 117:

if let indexPath = indexPath, indexPath.section != 0 && indexPath.row != 0 {
    return
}
descriptionTextView.resignFirstResponder()

Maybe I’m totally wrong, but for me it says: If indexPath doesn’t refer to the first cell in the first section (so the user tapped outside the descriptionTextView and cell) return and do nothing.

But when the user tapped outside the descriptionTextView resignFirstResponder() should be called to hide the keyboard …

Aaahhh, you’re right. :wink:

This is interesting: I actually changed this since the previous version of the book but it looks like I changed it wrong.

Thanks for pointing this out!