In Xcode to do development debugging often need to print some debugging information to do debug, you know when printing information in the place after the run on the simulator may not have any problem, because the simulator is the computer hardware but when the application runs on the device, these output statements will affect the performance of the application to a large extent, For this problem, you can write some macros to control the output of these debug messages.
Disable output of NSLog content in release version
Because the output of the nslog is more expensive than the system resources, and the output data may also expose the confidential data in the app, so the release of the official version of the need to screen out all of the output.
It is a dull and time-consuming thing to comment out all the nslog statements before we release the version, and then cancel the comments when we want to debug them later. Fortunately, there is a more elegant solution, is to add the following piece of code in the project's prefix.pch file, after joining, NSLog only in the debug output, release under not output.
How to achieve:
In the-prefix.pch (PCH full name is "precompiled Header", that is, the precompiled header file, which is stored in the project some infrequently modified code, such as the usual framework header file, so that the purpose of improving the compiler speed. We know that when we modify a file code in a project, the compiler does not recompile all the files, but compiles the changed files, if a file in the PCH is modified, then the other files contained in the PCH file will be recompiled once, which will consume a lot of time. So it is better to add the file inside the header file that is rarely changed or not changed or is precompiled Code snippet;) file to add
#ifdef DEBUG# define DLog(fmt, ...) {NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);}# define ELog(err) {if(err) DLog(@"%@", err)}#else# define DLog(...)# define ELog(err)
The last paragraph of the code means to replace NSLog with Dlog;
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
iOS development replaces NSLog print settings