Tarek
Tarek

Reputation: 823

Xcode variable debug visualized

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.

Upvotes: 1

Views: 746

Answers (3)

Julien Kode
Julien Kode

Reputation: 5469

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

Upvotes: 2

Rahul
Rahul

Reputation: 2100

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

Upvotes: 1

Owen Hartnett
Owen Hartnett

Reputation: 5935

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.

Upvotes: 1

Related Questions