如题,之前Xcode5的话是在prefix文件内import一次,就可以全局使用了,xcode6取消了prefix文件,替代的方法是什么呢?
没有什么替代方法,可能是苹果出于对项目构建或其他优化的考虑,不把预编译作为默认添加。
你可以自己手动添加进去。
- 1、Add new PCH file to the project - New file > Other > PCH file
- 2、At the project 'Build Settings' option - set the value of 'Prefix Header' to your PCH file name, with the project name as prefix - i.e. for project named 'TestProject' and PCH file named 'MyPrefixHeaderFile', add the value 'TestProject/MyPrefixHeaderFile.pch' to the plist.
至于为什么不作为默认添加项你可以看下这个链接的回答https://stackoverflow.com/questions/24158648/why-isnt-projectname-prefix-pch-created-automatically-in-xcode-6
Xcode6为什么干掉pch(Precompile Prefix Header)&如何添加pch文件
一直在用xcode6开发,但项目都是在xcode5上创建的,所以一直没注意到,xcode6竟然干掉pch文件了。
为什么xcode6没有自动创建pch文件呢?
简单地看:我们在写项目的时候,大部分宏定义,头文件导入都在这里,Xcode6去掉Precompile Prefix Header的主要原因可能在于Prefix Header大大的增加了Build的时间。没有了Prefix Header之后就要通过手动@import来手动导入头文件了,在失去了编程便利性的同时也降低了Build的时间。具体原因
StackOverFlow上讨论的已经比较清晰了
StackOverFlow:为什么xcode6没有自动创建pch文件呢?
如何在Xcode6中添加pch(Precompile Prefix Header)?
1,Command+N,打开新建文件窗口:ios->other->PCH file,创建一个pch文件:“工程名-Prefix.pch”:
2,将building setting中的precompile header选项的路径添加“$(SRCROOT)/项目名称/pch文件名”(例如:$(SRCROOT)/LotteryFive/LotteryFive-Prefix.pch)
可以了,编译一下程序,如果有错误检查一下添加的路径是否正确。
3,将Precompile Prefix Header为YES,预编译后的pch文件会被缓存起来,可以提高编译速度
-------------------------------------------------
(1)如果Precompile Prefix Header为YES,那么pch会被预编译,预编译后的pch文件会被缓存起来,从而提高编译速度。