Search code examples
objective-cdebuggingconditional-compilation

How to make debug code using #ifdef directive. Objective-c


i want to make a question about developing using #ifdef directive.

I want do make some code in objective-c only for debug use, for example:

in main function do this:

#define DEBUG_LEVEL

in my interface do this:

#ifdef DEBUG_LEVEL
BOOL editorIsDragged;
BOOL editorIsSelected;
#endif

.... other property

#ifdef #DEBUG_LEVEL
@property (nonatomic, readwrite) BOOL editorIsDragged;
@property (nonatomic, readwrite) BOOL editorIsSelected;
#endif

then in my implementation do this:

#ifdef #DEBUG_LEVEL
@synthetize editorIsDragged, editorIsSelected;
#endif

but i receve an error because in synthetize editorIsDragged and editorIsSelected are not defined. If i try to define my own setter/getter method I receive the same error, because my vars (editorIsDragged and editorIsSelected) does not exist for XCode!

I in C use this method for write only debug code, but in obj-c what i must use??

thank you!


Solution

  • Shouldn't you put your #define DEBUG_LEVEL in a header file that gets included in all places that needs to know it? Like setting in in the build settings or putting in the *.pch. And I'm not sure if that a typo but you have also #define #DEBUG_LEVEL (see the second hash?) in the code here.