Please consider subscribing to Mobile Developer Tips RSS feed or following us on Twitter
|
|
|
In a previous post, Yet Another Debug Output Replacement, I wrote a macro that I prefer over NSLog as the output does not prepend the date/time and object information that NSLog does.
Since that time I’ve pulled together a few more macros that I use on a regular basis for printing debug information on rectangles, points and sizes. I’ve also included a means to turn debug information on/off so debug statements are not included in builds targeted as final releases.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Debug
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#define DEBUG_ON // Toggle to DEBUG_OFF to hide all debug code
#ifdef DEBUG_ON
#define debug(format, ...) CFShow([NSString stringWithFormat:format, ## __VA_ARGS__]);
#else
#define debug(format, ...)
#endif
#define debugRect(rect) debug(@"%s x:%.4f, y:%.4f, w:%.4f, h%.4f", #rect,
rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)
#define debugSize(size) debug(@"%s w:%.4f, h:%.4f", #size, size.width, size.height)
#define debugPoint(point) debug(@"%s x:%.4f, y:%.4f", #pt, pt.x, pt.y)
Related posts:
- Yet Another Debug Output (NSLog Replacement)
- Write Debug Output to a File
- Conditional Compilation
Comments
3 Responses to “Debugging Macros”
Leave Comment
You can also use NSStringFromRect(), NSStringFromSize(), NSStringFromPoint().
[Reply]
I also suggest defining your DEBUG_ON as a per-target preprocessor macro in the target’s build options rather than inside a header. That way you don’t need to worry about remembering to turn it off when you build for distribution.
[Reply]
Great suggestion, thanks Will.
Can you explain the specifics for setting the per-target preprocessor macro in the build options? That insight would be very helpful.
Thanks
John
[Reply]