Graphics Programs Reference
In-Depth Information
A quick tip on logging
In this application, you log a lot of data to the console. It would be easy to miss an import-
ant log statement. One way to catch important statements is to prefix the most important
ones with an easily searchable token (like xxx ), but that's a quick-and-dirty fix.
A more elegant and useful option is to define a preprocessor macro that you can use to
categorize your log statements. For example, in Nerdfeed , you can generate a ton of log
statements for checking the input and output of your web service requests. You can also
generate a ton of log statements for checking the logic in the rest of the application. When
you are debugging Nerdfeed , it would be helpful to separate the web service-related state-
ments from the others so that you can turn them on or off as needed.
While there are many ways to do this, here is the simplest one:
#define WSLog(...) NSLog(__VA_ARGS__)
This statement tells the compiler, “When you come across WSLog , see NSLog .” Save this
statement in its own .h file and import it into your precompiled header ( Nerd-
feed_Prefix.pch ). Then, when you want to log a web service-related statement in
your code, use WSLog instead of NSLog , passing the exact same arguments. For ex-
ample, in ListViewController.m , you could change the log statement in connec-
tionDidFinishLoading: to the following:
WSLog(@"%@\n %@\n %@\n", channel, [channel title], [channel infoString]);
As long as WSLog is defined to NSLog , nothing will change. You will still see all of your
log statements in the console. When you want to turn off the web service-related state-
ments to concentrate on other areas, simply re-define WSLog to the following in its header
file:
#define WSLog(...) do {} while(0)
Now any WSLog calls will be invisible to the compiler, so they will not appear in the con-
sole to distract you from your non-web service debugging. (Defining WSLog in this way
means it will be optimized out by the compiler.)
Search WWH ::




Custom Search