Apollo
Apollo

Reputation: 9054

excluding NSLog's from release version of iPhone app

Could somebody go over how to exempt NSLog's from a release build of an app? Also, does it matter if comments are left in a release version? Thanks!

Upvotes: 4

Views: 1492

Answers (4)

samson
samson

Reputation: 1152

Is this not ALREADY NSLog's behavior? I thought that was the whole point...

Upvotes: 0

EmilioPelaez
EmilioPelaez

Reputation: 19892

What I do to exclude NSLogs is to add this to the prefix file:

#define NSLog(...)

That way, when compiled, all NSLogs will be replaced with nothing, it will be like an empty line.

As for the comments, they never make it into the binary at all, those are ONLY for whoever can see the source code.

Upvotes: 2

Kurt Revis
Kurt Revis

Reputation: 27984

Use a macro like DLog to wrap NSLog, and turn it off in Release builds.

#ifdef DEBUG
#    define DLog(...) NSLog(__VA_ARGS__)
#else
#    define DLog(...) /* */
#endif

Comments absolutely don't matter. They are only in your source code, not the compiled output. You don't submit your source code to Apple, only the built copy of your app.

Upvotes: 6

El Developer
El Developer

Reputation: 3346

The newer versions of the Xcode projects usually include a macro definition DEBUG when building for a debugging version, so the easiest way would be to go for:

#ifdef DEBUG
NSLog(@"Safe and sound ...");
#endif

It doesn't really matter though, in my experience sometimes you don't want the console to be vomiting a bunch of logs, you probably only need them at certain occasions.

Upvotes: 1

Related Questions