Xcode6以后预编译pch文件的添加

在Xcode6之前,新建一个工程的时候,系统会帮我们自动新建一个以工程名为名字的pch (precompile header)文件,在开发过程中,可以将那些整个工程都广泛使用的头文件包含在该文件下,编译器就会自动的将pch文件中的头文件添加到所有的源文件中去,这样在需要使用相关类的时候不需要使用import就可以直接使用头文件中的内容,很大程度上带来了编程的便利性,但潜在的也带来了一些问题,这也是在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 (likeFoundation.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.

那么有时候我们还需要pch文件,尽管会有一些问题,但是在项目开发过程中使用pch文件还是有一定的便利性,处于习惯将添加方法贴在下面,同时在路径方面我采用了相对路径,这样的话可以避免在代码管理或者移至其他文件夹后出现路径找不到的问题出现

Xcode6以后预编译pch文件的添加_第1张图片
Xcode6以后预编译pch文件的添加_第2张图片
Xcode6以后预编译pch文件的添加_第3张图片

你可能感兴趣的:(Xcode6以后预编译pch文件的添加)