XCode6 生成prefix.pch文件

        XCode6里, 新建工程默认是没有pch文件的,苹果取消pch文件这一点肯定有它的道理,刚开始很多人可能不适应,如果我们想使用pch文件,需要手动添加,添加步骤如下:(依旧直接上图)



      @ 取消的原因:

      Stackoverflow上有一个人对此的解释是这样的:
       I suspect because of modules, which remove the need for the  #import <Cocoa/Cocoa.h>.
       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.


       翻译过来 大致就是说 也许是因为组件单一模块的原因,所以 放弃了对<Cocoa/Cocoa.h>的import
       你不应该在你的prefix代码中放入任何的代码,把他们放在你确实需要放入的文件中。把你的定义放到属于他们的文件中。 尽量不要使用宏定义(define)。。除非是非不得已的时候,(这里 插一句 不使用宏定义的原因是 宏定义是在预编译的时候处理的 因此 当你修改宏定义的时候 会导致大量的代码被重新编译 另外 宏定义存在许多潜在的bug 是因为在预编译的时候,他并不会被发觉到的)。如果你确实 在被逼无奈需要使用宏定义,把他们放在需要被include的头文件中,而不是放在prefix文件中。 
       prefix header文件是被那些大量使用 以及 几乎所有系统中的文件都需要被使用(例如 Foundation.h)。如果 你有一些东西大量存在,你应该重新思考你的架构问题你。因为 当你修改你prefix header的一些代码的时候,prefix header导致整个项目重新编译,这让你的代码重用变得困难,并且导致一些琐碎build的问题。所以 不要去使用prefix header 这样可以避免你大量的重新编译整个项目的时间 
       如果你仍然想要使用预编译,你可以创建一个新的并且传递给编译器的前段,这种方法很少见(我没用过),但确实是一个不错的方法

      @ 还可以参考:XcodePrecompilePrefixHeader浅析

      @欢迎转载!转载请注明:iOS@界迷糊小书童

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值