When I started learning Swift and iOS development, I used to love writing print() in my source code to debug and check the value. Here is an example of what I normally do:
And, the console result will be:
However, I soon discover there is a better way to do debugging using breakpoint.
Why use breakpoint?
The reason I believe it is better because of a few reasons:
- I won’t accidentally commit print(…) code into my project. I always have to remember to remove print(…) code after I have done my work, which I sometimes forget to remove.
- Following up on the first point, if I am printing certain sensitive data, printing in the log messages means giving people a chance to read the log and try to reverse-engineer or compromise the app.
- If you are working in a team and wants to share the breakpoints you set with others, you can do so in Xcode.
Hope the article helps you in your Xcode journey!