Edit Breakpoints in Xcode

iOS Tech Set
iOS App Development
3 min readFeb 5, 2018

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, Apple’s Debugging Tools page is a good reference.

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

--

--