The course is part of this learning path
This course focuses on advanced techniques in Swift. You'll be introduced to structs and how we can use them in our code.
Hi, within this lecture we're going to learn about Breakpoints. So, breakpoints are literally the points that we want to take a break from running the code. So, it's spelled like this. And I'm going to show you a showcase. And in here I believe we have to comment out this print so that we would have a clear look at over here, okay? So, let me comment out this as well and let me come over here to have a very simple example. And this gives me an error because we have to have some statement in the switch and case. So, let me leave this as it is. We will see that it's 1-3 things but it won't matter. For example, I'm going to create a variable over here, okay? And I'm going to assign this to be a number. And then later on I'm going to change this number and I'm going to try to figure out where I am changing this number. So, let me say that let x is 5 and let's make it variable rather than constant because we're going to change it. And let's print out this x. And then later on I'm going to add one to this and print out one more time. For example, let's suppose that I have a very complex code in my project. And I'm trying to put the value of x in a label. So, it prints out 6 as it's supposed to, as you can see it prints out 5 and then 6, and because it's really 6. But for some reason suppose that I cannot figure out why it's printing out 6 or why it's showing 6 in the label. So, I'm trying to find where I'm adding one to this. For example, if I click over here in the line 158. Now, when I run this, it will stop my code, it will stop executing my code at the breakpoint. Like I have crashed the application. Of course it's not a crash, it's just a breakpoint and it will give me opportunity to debug this code. And as you can see now, we see all the variables, all the objects that we have created in this file and also we see the values, we see the current values, they are assigned to those variables. So, this is a very good, very comprehensive information to debug. Now, I can just see that my x is 5 for example. So, I know before line 158, I believe, yes. Before line 158 it was okay it was still 5. Now, if I come over here to 159 and I can just drag this and drop over here to delete it and if I run this one more time then I will see all the values one more time. And now I see my x is 6. Now, I can know that I know that before line 158 it was five. Now, I'm having this issue in line 158. Of course, this is too obvious and you cannot understand the importance of this. But in a very complex code, you would find this very helpful to stop the code and see all the values assigned to all the variables. Because maybe you're not looking for a single value. Maybe you're looking for a data that you download from the Internet or maybe you're looking for a very complex set of arrays, okay? So, either case this will be very helpful when you try to debug your code and beginners actually by accident tap on these lines and they add breakpoints and they don't know how to delete them. So, you can delete them by dragging them out of your code. So, that's it. Let's stop here and continue within the next section.
Atil is an instructor at Bogazici University, where he graduated back in 2010. He is also co-founder of Academy Club, which provides training, and Pera Games, which operates in the mobile gaming industry.