Skip to content

Instantly share code, notes, and snippets.

@hallski
Created August 18, 2010 12:09
Show Gist options
  • Save hallski/534487 to your computer and use it in GitHub Desktop.
Save hallski/534487 to your computer and use it in GitHub Desktop.

Simple debug method that takes a block

A very simple debug method that takes a block and only executes it if the DEBUG flag is set.

In Xcode you set this by adding

DEBUG=1
to Preprocessor Macros in your Project Build Settings for your Debug configuration.

/*
* debug.c
* Easy Shop
*
* Created by Mikael Hallendal on 2010-08-18.
*
*/
#include "debug.h"
void debug(DebugBlock debugBlock)
{
#ifdef DEBUG
debugBlock ();
#endif
}
/*
* debug.h
* Easy Shop
*
* Created by Mikael Hallendal on 2010-08-18.
*
*/
typedef void (^DebugBlock)(void);
// Method that takes a block and only executes it if DEBUG is set
void debug(DebugBlock debugBlock);
/*
* Simple example of usage
*/
#include "debug.h"
int
main(int argc, **argv)
{
debug(^ {
// Your debug code here
});
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment