Premise: When xcode is used for development and debugging, it is often necessary to print some debugging information for debugging. As you know, when there are too many information to print, it may not be a problem to run on the simulator, because the simulator uses computer hardware, but when the application runs on the device, these output statements will greatly affect the application performance, to solve this problem, you can write some macros to control the output of the debugging information. The nslog content cannot be output in the release version:
Because nslog output consumes system resources, and the output data may expose the confidential data in the app, you must block all the output when releasing the official version.
We can comment out all nslog statements before releasing the version, and cancel the comments before debugging. This is really boring and time-consuming! Fortunately, there is a more elegant solution, that is, the prefix in the project. add the following code to the PCH file. After the code is added, nslog is output only under debug, but not under release.
How to implement: In-prefix. PCH (PCH stands for "precompiled header", that is, the pre-compiled header file. Some codes that are not frequently modified in the project stored in this file, such as common framework header files, this aims to increase the compilation speed of the compiler. We know that when we modify the code of a file in a project, the compiler does not recompile all the files, but compiles and modifies the files. If a file in PCH is modified, in this case, other files contained in the entire PCH file will be re-compiled, which will consume a lot of time, therefore, it is best to add files that are rarely changed or do not change the header file or pre-compiled code snippets;) add files
#ifdef DEBUG#define NSLog(...) NSLog(__VA_ARGS__)#define debugMethod() NSLog(@"%s", __func__)#else#define NSLog(...)#define debugMethod()#endif
The code in the previous section refers to the macro command to make a judgment. If debug is true, the # ifdef to # endif macro definition will be compiled; otherwise, the compiler will not compile the Code;
Where can I set this debug,
There is a "DEBUG = 1" in "target> build Settings> Preprocessor macros> debug ".
In debug mode, nslog can be printed when product --> scheme --> schemeedit scheme is set to build configuration to debug. Set release and the app version will not be printed when released, improving performance.