XCode6 生成prefix.pch文件

        XCode6裏, 新建工程默認是沒有pch文件的,蘋果取消pch文件這一點確定有它的道理,剛開始很是多人可能不適應,假設咱們想使用pch文件,需要手動加入,加入過程例如如下:(依然直接上圖)html



      @ 取消的緣由:xcode

      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淺析less

      @歡迎轉載!轉載請註明:iOS@界迷糊小書童ide

相關文章
相關標籤/搜索