Project 18 (part 2)
Day 65 is the second part of the eighteenth project which, again, involves writing very little code since it is about debugging. You do a review and then he gives you three “challenges”, which are pretty much just illustrations of how you might debug something. He challenges you to add an exception breakpoint in Project 1 and then force it to throw an exception by giving it a bad identifier to instantiate a view controller from. He challenges you to add an
assert that will verify that there is a
selectedImage in the
DetailViewController in Project 1. And he challenges you to add a conditional breakpoint to the start of the
submit method in Project 5, that will trigger if the user submits a word with six or more letters.
For the first one, I just added an exception breakpoint in the breakpoints window and changed the identifier in
"Bad". When I ran the app and tapped on a cell it paused because an exception was thrown and it looked like this:
For the second challenge I just added this line in
1 2 // In viewDidLoad() assert(selectedImage != nil, "We should never be on this view without an image.")
It runs just fine because everywhere we are instantiating a
DetailViewController, we are also passing a
selectedImage. That may change in the future though, so it doesn’t hurt to check.
And for the third, I added a breakpoint at the beginning of
submit() and gave it the condition
answer.count >= 6. When I ran it in the app and submitted a word with fewer than 6 letters, it didn’t pause, but when I submitted a word with more than one letter it paused on that line. It looked like this: