Use of PCH files in IOS and use of PCH files to eliminate all NSLog functions in the project

Source: Internet
Author: User

In the actual project, we may need some global macro definition or a file, and be reused. Obviously, if you define a macro in each project file, it is very troublesome, today we introduce a file PCH file, only. h file.

PCH file: For a macro definition, the equivalent of a declaration file, the file is global. You can also understand that, after he sets the path, it is imported into individual files in the project by default. But can not take this as the conclusion, specific, you own Baidu bar.

How to create a 1,pch file

1), in the project Commond+n select the other red H file (below the PCH file) Click Next to give him a name, and then creat on the line. Here's the picture, yes, that's it.

2) After the first step, what you need to do is to set the PCH path, not set, your PCH file can only be soy sauce star.

How do I set the path?

(1), click on build Settings input prefix search, find Apple LLVM 6.0-language (note ha, 6.0 is the version of Xcode, different Xcode is different, do not tangle this, know). There's a prefix Header behind it. Double-click to enter a box in the input box, type $ (srcroot)/project name/pch filename. pch, this is the format and do not forget the suffix of the PCH file. The time has come again.

(2), see the line above the input box precompile Prefix header? It defaults to no, set to Yes, as if it can be created in your PCH file two times after the operation, improve efficiency, specific Baidu.

Reader: For God horse and our own Baidu?

Author: I am a rookie 55555, a lot of do not understand, can only show this thing, you do not embarrass me.

The use of 2,pch files. have been created, directly with Isaac.

Look inside the PCH file, see the Avfoundation header file I introduced? By the way, the others are like me.

Did you see that kscreen? , it is a macro definition, others, as I do. Yes, you can use it globally.

3, how to eliminate the NSLog function in the project?

The point is, we are in the process of the project, we may need to test what, write a lot of nslog function, output a mess of things. Now the project is finished, these nslog functions, want to let them shut up, don't talk, but can not find them, swollen?

I teach you a trick.

Look at the picture. (Reader: Another picture---.) ----)

This piece of code, is a whole, write to the PCH file anywhere in the line. Note that any place is OK, do not believe you can try.

Author: Reader, have you finished?

Sure you've finished?

After reading, the copy of the code to save, do not knock.

Eliminate the NSLOG function in the file #ifdef __optimize__#define NSLog (...) NSLog (va_args__) #else # define NSLOG (...) {} #endif

Use of PCH files in IOS and use of PCH files to eliminate all NSLog functions in the project

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.