xcode6如何添加並配置pch文件

1. 在Xcode6之前,新建一個工程的時候,系統會幫我們自動新建一個以工程名爲名字的pch (precompile header)文件;

2. pch文件用途:在開發過程中,可以將那些整個工程都廣泛使用的頭文件包含在該文件下,編譯器就會自動的將pch文件中的頭文件添加到所有的源文件中去,這樣在需要使用相關類的時候不需要使用import就可以直接使用頭文件中的內容,很大程度上帶來了編程的便利性;

3. 問題:但潛在的也帶來了一些問題,這也是在Xcode6中默認不再創建pch的原因吧。

As to where to put code that you would put in a prefix header, there is no code you should put in a prefix header. Put your imports into the files that need them. Put your definitions into their own files. Put your macros...nowhere. Stop writing macros unless there is no other way (such as when you need __FILE__). If you do need macros, put them in a header and include it.

The prefix header was necessary for things that are huge and used by nearly everything in the whole system (like Foundation.h). If you have something that huge and ubiquitous, you should rethink your architecture. Prefix headers make code reuse hard, and introduce subtle build problems if any of the files listed can change. Avoid them until you have a serious build time problem that you can demonstrate is dramatically improved with a prefix header.

In that case you can create one and pass it into clang, but it's incredibly rare that it's a good idea.

(翻譯:

在那裏,把你的代碼將在一個前綴標題,沒有代碼應該放在一個前綴的頭。把你的輸入需要的文件。把你定義爲自己的文件。把你的宏……一事無成。停止寫作宏除非沒有其他的方式(比如當你需要__file__)。如果你需要的宏放在一個標題,包括

前綴標題的東西是巨大的,幾乎在整個系統中所用的一切東西都是必要的(如基礎。H)。如果你有巨大的和無處不在的,你應該重新考慮你的建築。前綴標題使代碼重用困難,並介紹了微妙的構建問題如果列出的文件可以改變。避免他們直到你有一個嚴重的建造時間問題,你可以證明一個前綴報頭大幅改善

在這種情況下,你可以創建一個並把它傳遞到鏗鏘但它是非常罕見的這是個好主意

)


但有些時候,還是需要pch文件的,那麼怎麼在Xcode6中添加一個pch文件呢?

首先,Command+N,打開新建文件窗口:ios->other->PCH file,創建一個pch文件,添加需要引入的頭文件名:




其次,修改工程配置文件,將剛剛創建的PCH file的路徑添加到building setting中的precompile header選項中去,注意debug和release兩欄都要添加:

在TARGETS-》bundle setting-》


完成。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章