Swift Components Tour – Breakpoint Management

In this lesson

Back in the Swift Components Tour app, let’s talk about how to manage your breakpoints in Xcode.

Kyle Roberts
Swift Guru at Large

Kyle's Series


Tap on time to skip ahead


Hello world, Kyle here with Brax.tv. Today we’re going to talk about how to manage breakpoints. We can see here that in the TextFieldViewController, that I have four breakpoints on the four lines in viewDidLoad, so that when I do open this view controller we should hit each of these breakpoints. We can just continue over with this play/pause execution button down there. We’ve just continued past all four of those breakpoints. We didn’t really need to know anything that was going on there.


What if we wanted to get rid of them or temporarily disable of them while we work on something else? There’s multiple ways to do this. First, we will get rid of a breakpoint. Here on this line we’re just calling super.viewDidLoad, that’s not something that we’re going to want to pay attention to because we call this method every time we implement the viewDidLoad method. To remove this breakpoint, you click and hold, and just drag it off until there’s a little X button by the cursor, and you let go, and poof, the breakpoint is gone.


Let’s say that what we’re worrying about here is this self.startAnimatingLabel method. Why don’t we go ahead and remove these other two breakpoints here since we could just use this step over in or out of buttons to continue through the rest of this method’s implementation. Again, with those, I just clicked and dragged them off of this breakpoints/line numbers bar here. I don’t have line numbers turned on at the moment but this is where they show up. If we run the app, then we will only hit this one breakpoint here when we open this view controller in viewDidLoad. We can continue program execution down here again and continue with the app how we normally would use it.


How about during run time while the app is still running, what if we want to open this view controller but we don’t want to hit this breakpoint? We’ve already hit it, we know what’s going on. Maybe we want to see what’s happening in real time when the app is running without it pausing on us. But we still maybe want to come back later and remember to check over this breakpoint again. What you can do is deactivate it. How you deactivate a breakpoint is you just click on it. You can see that it turns slightly translucent so that you know that it’s still there, but as we’re using the app, and I will open this view controller again, we are not going to hit that breakpoint on viewDidLoad. But it’s still there. If I go over here, and I click on it again, we’ll reactivate it and then we can open this view controller and we will hit that breakpoint.


For this next example, I’m going to add those other three breakpoints back in and we’ll just continue the program execution past that. There’s something called a breakpoints navigator up here in the top left of the screen. This shows you a list of all active or inactive breakpoints in your code in the project. We can see here that in the TextFieldViewController, I have four breakpoints in the method viewDidLoad. There’s all active with their respective line numbers next to that. What happens if we add another breakpoint down here, in textFieldShouldChangeCharactersInRange. Let’s just do that. We can see that this method definition here is different and actually pointing to the method the breakpoint is in and the line number matches as well. If we deactivate that, it will show us in this navigator as well that that breakpoint is deactivated.


Some more management that you can do in this breakpoint navigator up here, is you can actually click these breakpoint symbols up here to activate and deactivate them. We can just deactivate them all. If we wanted to remove them, you can actually remove them by pressing delete or backspace, Mac’s have a delete key. Here we can just delete over all of the breakpoints that we have in the app.


If we put one back and I’m just going to show you another example in the TextViewViewController. We’ll just plop a breakpoint anywhere in this view controller. Actually, let’s not use the viewDidLoad method, let’s put it in keyboardWillHide. We can see here that we have one active breakpoint in viewDidLoad on line 22 of TextFieldViewController. In the TextViewViewController, we have an active breakpoint on line 34 of keyboardWillHide. Pretty cool. Thanks for watching.

Additional Info

Register to get access to additional resources and info.