1

Is there a way to debug a bunch of variables and see their contents live while running the simulator?

I know I can access variables immediately from the console/debug window if I use breakpoints but what I'm looking for is a bit different.

4
  • 1
    As far as I know, you can't do a live debugging. You can only see the variables content when the app is paused. But you can add observers to your object, and print their values to the console. So, you will be informed when they change their values Commented May 9, 2017 at 14:44
  • What about viewing all lines of code that write to a specific variable? Is that possible? Commented May 9, 2017 at 14:48
  • 1
    Do you mean, other codes that modify your variable? Right click to this variable (in the definition) and select "Find call hierarchy" Commented May 9, 2017 at 14:52
  • I believe call hierarchy only shows where a variable was defined. Am I missing something? Commented May 9, 2017 at 15:05

3 Answers 3

2

Is there a way to debug a bunch of variables and see their contents - live - while running the simulator?

Yes in Xcode you can use po to see your object when you are on your breakpoint:

Just type in the console:

po myvariable

I've made a little example for you:

I create a variable, I set it to one, and I put a breakpoint. I access to the console to see the value of my variable po myvariable

I set the variable to two and I retype po myvariable to see the new value of my variable po myvariable

Sign up to request clarification or add additional context in comments.

2 Comments

@Tarek Unless you can read REALLY quickly you're not going to achieve that.
@Tarek I understand, but use this way is good, I'm currently thinking about a new solution for you
1

Yes, you can do this, by editing breakpoints: At the point where you want to see your variable's value, add a breakpoint. Then right click it to "edit breakpoint." Click "automatically continue after evaluating actions." Click "Add Action" Note that after you do this, there is a + and - control to add more actions. Choose "log message" and type in a string so you'll know what variable value you're about to display. Click the + button, leave it at "Debugger Command" and type "po name-of-your-variable" (replace with name of your variable, of course) Now when your code hits this point, it will print the log message and value in the console and continue execution. Repeat to taste.

2 Comments

Note that this technique is often more useful than sprinkling NSLogs throughout your code.
That's the closest thing to what I wanted. Thanks for explaining how the extra options Breakpoints have work :)
1

Apart from using po to inspect an object in lldb, Xcode provides a nifty feature to print the description in the console.

enter image description here

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.