The PCH file for iOS learning

Source: Internet
Author: User
Tags uikit

1. pch File overview
    • PCH file is a precompiled header file (a generic extension of. PCH) is a project in which the more stable code is pre-compiled and placed in a file (. PCH). These pre-compiled code can be any C/s code--or even an inline function--that is more stable throughout the project, i.e. code that is not often modified during engineering development.

    • In the previous version of Xcode6.0, the PCH file was automatically present in the generated single View application project, and the PCH was removed afterXcode6.0 , which accelerated the compilation speed for some trivial header file references!

    • Works for the XCODE5:

2. pch File Creation (Previous versions of Xcode6.0)

In Project Command + n-> in iOS other-> PCH file-> next-> Create

PCH files are compiled in advance, so we're going to tell the project. Specific operations such as:

Of course, if you want to fill in, you can use $ (srcroot) to get the path of your project file, complete can be written as:$ (srcroot)/pchtest/header.pch

3. The role of PCH files
    • Store some of the common macros

    • Store some common header files , general development of the Chinese tool class header files or classification header files.

    • Managing log Output

custom log: #define ZFLOG (...) NSLog (__va__args__)

Variable parameters inside the macro:...

Variable parameters in the function :__va__args__

  Log output is very performance-intensive, generally released when the log file is not required, only when debugging.

We have two simple ways to eliminate all log output in the project when it comes to the launch.

① we can comment directly behind #define ZFLOG (...) //NSLog (__va__args__)

②   You can also conditionally compile with a macro, and in the debugging phase, Xcode automatically defines a debug macro , using this macro, you can make conditional compilation.

#ifdef // Commissioning Phase #define Zflog (...) NSLog (__va__args__) #else//  release phase #define zflog (...) #endif
4. pch File Usage considerationsInPchwritten about OC , preferably in #ifdef __objc__ ,Xcode defines this macro in each OC file, which means that only oc Files in the file to have these macros, to avoid the project has a C file when the error. such as inCfile, use the#import,you will get an error, becauseCFile not recognized#import, onlyOC file to be recognized. In pch c file share #import error.
#ifdef // the correct notation    for OC files #import <UIKit/UIKit.h>    #import <Foundation/Foundation.h>#endif# Import"ZFTool.h"//  write here may error, so do not write here

The PCH file for iOS learning

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.