Use Breakpoint instead of print(…) to debug your app

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:

  1. 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.
  2. 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.
  3. 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!

Leave a Comment

Your email address will not be published. Required fields are marked *