HalR
HalR

Reputation: 11083

How can I debug effectively with blocks in Xcode

I'm really struggling with debugging code on our big ios project. It seems like everyone has gone nuts on putting blocks and dispatch queues everywhere.

When I'm asked to debug a chunk of code, I really like to step through it and watch how things change, and see what is really happening with variables. I can't really do that easily with all the blocks that have been put in for two reasons:

  1. I have to put a breakpoint within each little block to stop in that block.

  2. Within a block, the variables from without the block are not displayed in a useable fashion, and can't be easily dumped to the console with a po command.

Is there an easier or better way to step through/evaluate code that is rife with blocks? Or am I missing something here?

Upvotes: 10

Views: 4671

Answers (4)

Balazs Nemeth
Balazs Nemeth

Reputation: 2332

Do you use breakpoint with automatically console dump (without stopping your running app)?

There is a far from excellent, but really usable tutorial about intermediate debugging.

Happy coding!

Upvotes: 3

Tobi
Tobi

Reputation: 5519

You are right, it is a bit cumbersome to debug blocks. I tried using "auto-dump-breakpoints" but it turns out, that they are horrible to maintain...

I ended up using basically NSLog. But the problem with NSLog() is, that you don't want to have all that logging in your release build. So I would recommend to use a tool like:

MWLogging

I think it's really great. You can read about that and logging in general in this blog post:

iOS Development: You're Doing It Wrong

it's really worth reading.

Upvotes: 1

lakshmen
lakshmen

Reputation: 29094

You can print out the object in the console, using this:

Example:

po object.name
po object.age

Another way: Put a breakpoint at the code. When it stops execution at that point,hover over it.

For more clear detail, look at my answer for this question: How to inspect elements from NSArray and NSDictionary in xcode?

Upvotes: 1

AndrewShmig
AndrewShmig

Reputation: 4923

Why not use NSLog() to output needed variables in blocks?

Upvotes: 1

Related Questions