Xcode的build setting

weixin_34337265發表於2016-06-07

Xcode裡面有很多很神奇的編譯設定,特別是Xcode7以後又有很多的變化,這裡做一個歸納

  • Enable Testablity
    這個選項的意思是,當你需要用到UI測試的時候,有一個關鍵字@testable,用於自動引入要測試的類,譬如
@testable import TestViewController

建議在debug狀態下開啟該選項
參考連結
UI Testing in Xcode
How to Implement UI Testing in an Existing iOS App
Xcode:為你的專案整合單元測試(unit tests)時記得避開這些坑

  • Weak References in Manual Retain Release
    如果你升級了xcode7.3以後的版本,有可能會在編譯時報錯,主要針對的是MRC檔案混編的場景。在我們的專案中也有遇到類似的問題,譬如如下程式碼
+ (id)getNewValueFromObject:(__weak id)object oldValue:(__weak id)oldValue property:(__weak MJProperty *)property;

MRC檔案混編的時候會出錯,解決辦法是將這個編譯項設定為YES就好了。簡單來說就是在MRC下也能夠支援__weakruntime特性了。
參考連結
xcode7.3編譯問題
<a href="https://segmentfault.com/q/1010000004670789">iOS9.3 __weak reference</a>
<a href="http://stackoverflow.com/questions/36147625/xcode-7-3-cannot-create-weak-reference-in-file-using-manual-reference-counting">Xcode 7.3 cannot create __weak reference in file using manual reference counting</a>
Xcode 7.3b4, non-arc, cannot create __weak reference
Xcode 7.3 Cannot create __weak reference in file using manual reference counting

  • Enable On Demand Resources

這是IOS9的新特性,跟App減少包體積有關。不過實際情況不太樂觀,簡單來說他的實現方式是,App先標記好哪些圖片是需要按需載入的,然後提交全量包到AppStore。當使用者下載App的時候,將不會下載標記的圖片,等到App需要後載入資源的時候再下載。資原始檔的託管是在AppStore伺服器上。所以如果你想要使用該技術的話,要先做以下步驟

  1. 將這個設定項設定為YES
  2. 標記資源
  3. 使用指定的api按照tagid下載資源

參考連結
關於iOS9的APP瘦身
按需載入資源開發指南
On-Demand Resources Guide

相關文章