Leave a rating/review
Now that you’ve learned how to pause and continue your app, let’s learn a little more about how to control breakpoints.
In the previous video, you just set one breakpoint in the body of RowView. There must be something that’s causing tasks with different priorities to not show up. Let’s add two more breakpoints to see how things are executing.
Open TaskStore.PrioritizedTasks.swift. Add a breakpoint on line 42. Now open TaskStore.Swift and add a breakpoint on line 67. Now, build and run your app once again using the simulator. You see execution pauses at the breakpoint you just set.
Click Continue four times and execution should now pause at the second breakpoint you set.
“Continue” basically tells Xcode: “continue running until you hit another breakpoint, then pause again when you do”. If no other breakpoint is hit, execution continues normally, but if one is hit, execution pauses there. This lets you pause at different points in your app in order to see see what’s happening “under the hood”.
Click Continue again until you, it should be seven clicks you need, and the third breakpoint should be hit. This is where the check is made to determine whether the checkmark is shown for a task’s row or not.
Click Continue several times and notice how Xcode just kind of flashes and the line stays on your breakpoint.
Don’t worry, your breakpoints didn’t “break” Xcode, it’s just that they are called more than once as our code and SwiftUI work behind the scenes to set up your model and display it on-screen.
This brings up an issue with breakpoints. Sometimes you want a breakpoint to exist, because you’re going to use it later, but you don’t want execution to stop there right now.
You can delete a breakpoint, and we’ll take a look at that how to do that in just a minute, but in this case you just want to disable the breakpoint. The easiest way to disable one breakpoint is to click on its indicator in the line number.
Stop your app and open TaskStore.PrioritizedTasks.swift. Click on the breakpoint on line 42 a few times.
As you can see, each time you click on it, the breakpoint toggles between enabled and disabled. A disabled breakpoint is shown by the indicator turning pale. Leave this breakpoint disabled for now.
Click on the Breakpoint navigator. Click on the breakpoint within RowView.swift to disable it. Run your app once again and notice how execution now stops at the breakpoint you set in TaskStore.swift.
Disabling individual breakpoints is quite useful, but what if you have a lot of breakpoints and you want to turn them off all at once?. Do you have to find all breakpoints and disable them one-by-one? Fortunately not, there is a button precisely for this!
Since execution is stopped, click the Deactivate breakpoints button in the Debug Area to deactivate all breakpoints.
Open the breakpoint navigator and notice that all of your breakpoint indicators are turned gray, with a lighter gray for the ones you previously disabled individually.
Xcode will even save the enabled and disabled state of each breakpoint, so when you click the Activate/Deactivate breakpoints button again, all breakpoints reactivate to their last state.
Leave the breakpoints deactivated and click Continue. You can see that execution continues normally with none of your breakpoints being hit.
There is one other way to control breakpoints, and that’s by deleting them! You would usually disable a breakpoint if you plan to use it again, but if you’re done with a breakpoint you can just delete it.
Open RowView.swift and find your breakpoint. Click and drag the breakpoint indicator up and down, and notice how it moves to that new line of code. This is quite useful for repurposing an existing breakpoint, or perhaps to change where this breakpoint stops execution.
Now, click and drag to the right until the X indicator shows up. Let go of your click and the breakpoint will be deleted.
Open the Breakpoint navigator, and shift-select your two remaining breakpoints. Press Delete in your keyboard. Notice how this helped clean up multiple breakpoints at once.
Alternatively, you can also right-click, or control-click, on your selected breakpoints to bring up more options, including disabling the breakpoints as if you had clicked on them in the editor.
Great! You’re learning about more ways to work with and control your breakpoints. Now it’s time to focus on other things we can do once execution stops at any given breakpoint.
See ya in the next episode! :)