在Xcode6以前,新建一個工程的時候,系統會幫咱們自動新建一個以工程名爲名字的 pch (precompile header)文件,在開發過程當中,能夠將那些整個工程都普遍使用的頭文件包含在該文件下,編譯器就會自動的將pch文件中的頭文件添加到全部的源文件中 去,這樣在須要使用相關類的時候不須要使用import就能夠直接使用頭文件中的內容,很大程度上帶來了編程的便利性,但潛在的也帶來了一些問題,這也是 在Xcode6中默認再也不建立pch的緣由吧。ios
關於pch的得與失,stackoverflow上有段話講的比較透徹:http://stackoverflow.com/questions /24158648/why-isnt-projectname-prefix-pch-created-automatically-in-xcode-6編程
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.xcode
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.less
In that case you can create one and pass it into clang, but it's incredibly rare that it's a good idea.ide
但有些時候,仍是須要pch文件的,那麼怎麼在Xcode6中添加一個pch文件呢?ui
首先,Command+N,打開新建文件窗口:ios->other->PCH file,建立一個pch文件,添加須要引入的頭文件名:idea
其次,修改工程配置文件,將剛剛建立的PCH file的路徑添加到building setting中的precompile header選項中去,注意debug和release兩欄都要添加:spa
至此,大功告成,編譯一遍,新添加的pch文件就能夠正常使用了^_^。debug