標籤:log comm www ext 目的 .pch more any target
什麼是.pch檔案
先行編譯標頭檔(一般副檔名為.PCH),是把一個工程中較穩定的代碼預先編譯好放在一個檔案(.PCH)裡。這些預先編譯好的代碼可以是任何的C/C++代碼--甚至可以是inline函數,只它們在整個工程中是較為穩定的,即在工程開發過程中不會經常被修改的代碼。
我自己的理解就是 這個.pch檔案的作用就是 在這裡定義一些東西之後可以在整個工程內的任何一個檔案中使用在.pch
檔案中定義的東西 並且不用匯入任何的標頭檔
我的做法:
1.首先呢我會先添加一個.h檔案 用來寫宏定義
建立成功之後 可以在這個檔案裡邊添加 一些自己需要的宏定義
比如:我的
//// Header.h// My9xiuShow//// Created by TaoLi on 16/12/15.// Copyright ? 2016年 LSS. All rights reserved.//#ifndef Header_h#define Header_h//字型顏色#define RGBAColor(r,g,b,a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:a]#endif /* Header_h */
我只在這裡邊添加了一個宏
2.建立.pch檔案 建立檔案-選擇pch檔案
這樣就可以建立一個.pch檔案 SPrefixHeader
3.將Header.h 跟.pch檔案產生聯絡
開啟.pch檔案 添加 import “Header.h”
#import <UIKit/UIKit.h>#import <Foundation/Foundation.h>#import "Header.h"
代碼如下:
#ifndef SPrefixHeader_pch#define SPrefixHeader_pch// Include any system framework and library headers here that should be included in all compilation units.// You will also need to set the Prefix Header build setting of one or more of your targets to reference this file.#import <UIKit/UIKit.h>#import <Foundation/Foundation.h>#import "Header.h"#endif /* SPrefixHeader_pch */
4.將.pch檔案跟項目關聯起來
buildSetting- 搜尋prefix header - 找到Prefix Header
1 將Precompile prefix header 設定為yes 這樣的目的是編譯之後這個檔案會緩衝 這樣可以加快再次編譯的速度
2 Prefix Header 後邊雙擊 然後將建立的那個.pch檔案拖進去(一次不成功就多試幾次 然後就行了)拖進去之後將這個目錄做修改只剩下自己的 項目名/.pch檔案名稱 就像我的上那樣 My9xiushow/SPreficHeader.pch
5.這樣的話就大功告成了: 人後 commend+b 編譯下本項目 然後就可以使用了
如我:rgb這個宏定義就可以使用了
如若為水 為何不能嫌棄驚濤駭浪
iOS .pch檔案的使用