简体   繁体   中英

Using preprocessor macro to decide if app build is for debug or release

I want to log some events for debug builds. I have added below code in .pch file to log using DLog() in debug only. I have added IS_DEBUG macro in build setting.

#ifdef IS_DEBUG
    #define DLog(...) NSLog(__VA_ARGS__)
#else
    #define DLog(...)
#endif

To test if it works or not, I removed IS_DEBUG from build setting and ran app. Issue is that it always logs irrespective of debug/release app.

Please note that I tried changing the name of both DLog method and preprocessor macro to see it is due to same macro or method is defined somewhere else. But still it gives same issue, means same macro or method is not used else where.

In Xcode you are able to define Schemes. Each scheme can build to a specific configuration, usually at least Debug and Release. You can specify which you would like to use in the scheme manager in Xcode.

Next, in your targets configuration, you can change the macros that are defined for which configuration you'd like it to be associated with. In your case this would be 'IS_DEBUG'. Most likely you'd want to do this for the Debugging configtation, then create a scheme to build that configuration.

Bryan's answer helped me in solving this issue. Only cleaning project and Xcode cache did not work for me. I reset the simulator and cleaned project. It got it worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM