Edit Breakpoints in Xcode

iOS Tech Set
Feb 5, 2018 · 3 min read

Breakpoints play an important role in debugging, and Xcode offers powerful functions with them. Here are some tips with breakpoints to boost your efficiency while debugging.

Let’s get started.

Assuming we have a for loop as below:

var sum = 0for i in 0...100 {  sum += i}print(sum)

Q: I want to know sum value when i is equal to 60. How could I do that?

We could configure the “Condition” to do that. Here are steps:

  1. Set the breakpoint inside the loop
  2. Double click the breakpoint, or right click it and select “Edit Breakpoint”
  3. In “Condition”, fill out withi == 60

Now we know the sum is 1770 before adding i which is equal to 60 at the moment. We get it without a single line of code added, pretty simple, isn’t it?

Q: I want to know sum value only if i is greater than or equal to 90. How could I achieve that?

You may already notice there is a “Ignore” option below “Condition”. That is the correct answer: set “Ignore” to 90 so we do not need to worry about the sum value when i is less than 90.

Here breakpoint only hits when i has risen to 90, and right at the moment sum is 4005. You could continue program execution and witness each sum value with corresponding i greater than 90.

Q: I want to know sum value only if i is greater than or equal to 90. However, I do not want to manually continue program execution while hope to see all sum values at once. Is there a way to do that?

Yes, there is. “Action” and “Options” are just for this job. Here are the steps:

  1. Go to “Ignore”, set the value to 90 as previous
  2. Click “Add Action”, fill out with po sum , this means we will print the sum value
  3. Check “Options”, this means we will continuously output all sum values after i meet the requirement of “Ignore”
  4. [Optional] If you wish to know during which function the breakpoint is triggered, you can add an action with “Log Message” to output breakpoint name in the console.

Done! We get all sum values at once with i is greater than equal to 90. And we know all these happened in viewDidLoad().

Now you know some basic usage of breakpoints. For more interesting topics related to breakpoints or debugging, is a good reference.

Play with breakpoints and share your tips in the comments below and have fun!

iOS App Development

Stories and technical tips about building apps for iOS…

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store