iOS development replaces NSLog print settings

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.