Removing NSLogs for distribution

来源:互联网 发布:七妹电音软件 编辑:程序博客网 时间:2024/06/18 07:44

When developing an iOS or Mac app, NSLogs are very handy during development. These are quite useless for an app on an end users phone or computer, so removing every log is often a good idea, especially if you like to log a lot of information. This might sound like a pain, commenting out everyNSLog whenever you build for the AppStore? But no, there’s a much simpler solution, coming from our friend the preprocessor macro.

Every iOS and Mac project has a special file called <your project>-Prefix.pch. What does this mean? This is a precompiled header – a .h that is imported by every file in your project without the need to manually #import it. Combining this and preprocessor macros gives a very elegant solution to removing logs when building for the AppStore, and keeping them when developing.

Just put this into your pch:

#if DEBUG#warning NSLogs will be shown#else#define NSLog(...) {}#endif

Now try and build for development, you will get a warning telling you that logs will be shown. Build again for release and the macro replaces every NSLog (at compile time) with nothing.



原文链接:http://b2cloud.com.au/how-to-guides/removing-nslogs-for-distribution/

0 0
原创粉丝点击