5

In my memory, there's some code that can let the NSLog not work when released.

I don't want to remove my NSLog in my code.It helps a lot on debug mode.

So I want to find a way that can leave them in my code, and also don't slow down the application when released.

Thanks for your help~~

1

2 Answers 2

5

A common way to remove all NSLog(…) call in a release is to create a macro that is between conditional preprocessor macro and compiles to nothing, something like this:

#ifdef RELEASE
# define NSLog(...) //remove loggin in production
#endif

Put this code in a .h file that is included in every other file, like a Defines.h that is #include'd in the prefix header (.pch).

RELEASE should be a preprocessor macro defined against the Release configuration in the "Build Settings" tab of your target.

Apple LLVM compiler 4.0 - Preprocessing

Related Questions

Sign up to request clarification or add additional context in comments.

Comments

1

You will need to replace NSLog with a custom macro.

Put for instance

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

in your prefix pch file.

Use ALog for cases where you always want log output regardless of the state of the debug flag, and DLog for log only in debug mode.

Source

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.