IOS development replaces NSLog printing settings, and ios replaces nslog Printing

Source: Internet
Author: User

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.

Related Article

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.