IOS development replaces NSLog printing settings, and ios replaces nslog Printing
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 printing information, 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.
Disable NSLog 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 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 preceding Code replaces NSLog with DLog;
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.