[轉]Xcode6中如何添加pch檔案

來源:互聯網
上載者:User

標籤:blog   http   io   ar   os   使用   sp   for   檔案   

在Xcode6之前,建立一個工程的時候,系統會幫我們自動建立一個以工程名為名字的pch (precompile header)檔案,在開發過程中,可以將那些整個工程都廣泛使用的標頭檔包含在該檔案下,編譯器就會自動的將pch檔案中的標頭檔添加到所有的源檔案中去,這樣在需要使用相關類的時候不需要使用import就可以直接使用標頭檔中的內容,很大程度上帶來了編程的便利性,但潛在的也帶來了一些問題,這也是在Xcode6中預設不再建立pch的原因吧。

關於pch的得與失,stackoverflow上有段話講的比較透徹:http://stackoverflow.com/questions/24158648/why-isnt-projectname-prefix-pch-created-automatically-in-xcode-6

 

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.

 

但有些時候,還是需要pch檔案的,那麼怎麼在Xcode6中添加一個pch檔案呢?

首先,Command+N,開啟建立檔案視窗:ios->other->PCH file,建立一個pch檔案,添加需要引入的標頭檔名:

 

 

其次,修改工程設定檔,將剛剛建立的PCH file的路徑添加到building setting中的precompile header選項中去,注意debug和release兩欄都要添加:

 

 

至此,大功告成,編譯一遍,新添加的pch檔案就可以正常使用了^_^。

轉載自:http://blog.csdn.net/lihuiqwertyuiop/article/details/39268101

[轉]Xcode6中如何添加pch檔案

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.