Implementing the WatchKit Table Interface View
Try reloading this page, or reviewing your browser settings
This video segment walks you through using the Xcode debugger interface. Using the counter app as a demonstration case, you can see how the debugger allows you to monitor the functions your code is performing in real time, a powerful tool to have whenever building complex applications.
- Apple Watch
About this video
- Ravin Sardal
- First online
- 06 April 2019
- Online ISBN
- Copyright information
- © Ravin Sardal 2019
In this video, I wanted to talk about the Xcode debugger. And this is a really powerful tool that you will probably end up using throughout your development experience regardless of the language. But I wanted to show you how the debug tool in Xcode works.
So what the debugging tool allows us to do is it allows us to put breakpoints throughout the application. Now what is a breakpoint? A breakpoint is a point in the application which you want the program to pause. And what we can do when the program pauses is we can view all these states of the program.
So let’s say we have a game. In that game, we can put a breakpoint where the user, let’s say, presses on a certain button or a certain part of the screen. And what happens is the entire application freezes and it tells us what the state of that application is at that point in time. So the score of the player can be a certain number or the player’s energy level can be a certain level. So we can see what the variables of the application are at that point in time.
So let’s dive in to some live examples. So what I’m going to do is I’m going to put a point at the Will activate method. And I’m going to put a breakpoint at the Up button pressed method and the Down button pressed method. So now we can see when each function is executed and how our Xcode debugging interface looks like.
So let’s put those breakpoints. And the way you put a breakpoint is you just go to the left of the code right next the line number and you just click on it. And a blue breakpoint appears. And when you want to remove a breakpoint, you can just hold on the breakpoint and then drag it out. So lets hit Run.
And what’s going to happen is the application is going to open and it is going to freeze. So it’s going to be in this frozen state not being able to move. And let’s expand this view down here. So this view down here is our debugging interface. And underneath we have one line right here. And that’s self.
Self is Just a reference to all of the properties of this class right here– this extension interface controller class. So let’s expand self. And underneath self we can see a few different options that are in this interface controller. We can see our counter label outlet. This is one variable that we set up here. And then we can actually see our counter variable that we’ve set. So all these variables were initialized when the Will activate was called.
So we can see that we set our account to 0. And it shows the value of the counter variable. So we don’t want this to be paused anymore. So we can just resume our debugger. And that’s done by pressing this Continue program execution button right above it. And our app runs like normal. So this is how the app looks after the Will activate has been called.
So as you’ve noticed, I’ve put two more breakpoints on the Up button pressed and the Down button pressed functions. Let’s click the Up button. So I put the breakpoint right after– the counter is equal to counter plus 1– so right after the variable was incremented so we can see something happening to our variable.
So as you can see, the counter variable used to be 0. But now it’s 1 because our function was called and it was incremented. If you had more variables here, we’d see the state of those variables at that point in time. Let’s just resume it and continue. When we press Up again, we’ll see that counter shifts 2.
So we can really monitor all of our variables and what’s going on in our program through this interface right here. This is really helpful when you have large, complex programs and you need to debug and figure out what’s going on in a certain point of time and retrace your steps in the logic.
And again, when I press the Down button, it pauses and shows us that 3 was incremented to 2. And when we resume it, the UI updates. And how to disable these is you can either just drag them out. Or if you want to keep them there and just disable them, you can click on them. And they should turn into a darker shade of blue.
So yeah. That’s pretty much it. That’s how the debugger works. It’s really straightforward. And it’s an extremely powerful tool when developing applications.