Question

I've below code in my project dlog should print the values in console if isConsoleLogActive is YES.

It gives error like Operator 'defined' requires an identifier

#if defined ([Util isConsoleLogActive])// Operator 'defined' requires an identifier in this line
#define DLog(...) NSLog(__VA_ARGS__)
#define DTrace() NSLog(@"%s", __PRETTY_FUNCTION__)
#else
#define DLog(...) /* */
#define DTrace() /* */
#endif

if I use the same code([Util isConsoleLogActive]) in my .m it works perfectly fine. I face this issue only in #define

What could be the issue. Please give me some idea.

Was it helpful?

Solution

The various commands that start with # are preprocessor directives. These get executed before the compilation phase at build time, before your application actually executes. You should use the preprocessor directives to conditionally include different code in your application based on build configuration. The preprocessor, however, is the wrong way to handle conditional execution on a specific platform at runtime; for that, you want your standard "if...else" logic.

If your goal with that statement is to determine if the given selector exists, try respondsToSelector, instead.

OTHER TIPS

Result of

[Util isConsoleLogActive]

is not known at compile-time. So you can not use it with '#if defined'.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top