Xcoe6前系統會幫我們自動新建一個以工程名為名字的pch (precompile header)文件,之后的版本就要自己手動創建了。
接下來在build Settings 中搜 prefix Header然后添加路徑即可
(PS: $(SRCROOT) 用來表示相對路徑),輸入后會變成本地的絕對路徑
如上圖,然后在pch文件中import所需的頭文件即可
至于其引起的問題、官方文檔有給出(如下,具體還未看,復制到別人的),因此不再自動創建,但是這功能實在很方便,所以還是使用了……
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.