I would go even further:
DON'T USE LOG FOR DEBUGGING. (Yes, I really mean it.) More generally, don't EDIT code to figure out how it works.
Why?
Well, simply put: if you edit the code, you change it's behaviour and you'll end up debugging something else.
Just take this code example and add a print in the if.
int foo(bool bar)
{
int x = 42;
if (bar)
x = 58;
return 100 - x;
}
I hear you saying «I've only to add braces to the if and I'm good.» Yes, indeed, here it's
just braces... But think of what you would end up doing in a really complex function.
Now, don't forget one more important factor: everytime you edit your code to display some log, you'll have to edit it back to remove the log in your final app. This represents a HUGE amount of work in the long term and will most probably introduce other bugs.
Insead, learn how to use your debugger. Start here (
https://developer.apple.com/library/mac/documentation/IDEs/Conceptual/gdb_to_lldb_transition_guide/document/Introduction.html) or look for other tutorial.
Then you'll be able to (just to give you a few example):
- stop your app in the if statement
- print something (like x) in the if statement
- print something (like x) in the if statement without breaking (here = stopping) your app
- list variables' value
all of this WITHOUT editing your code.
And in a much faster way!I have to admit that at first it's hard to use a debugger but I hope this preachy talk will convince you and hopefully motivates you to overcome the first difficulties.