Day 65 - 100 Days of Swift

2 minute read

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 tableView(_:didSelectRowAt:) to "Bad". When I ran the app and tapped on a cell it paused because an exception was thrown and it looked like this:

Screenshot of an exception breakpoint being caught

For the second challenge I just added this line in DetailViewController.swift:

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:

Screenshot of a conditional breakpoint being caught

You can find my version of these projects at the end of day 65 on Github here.