有幾回遇到從網上下載到的iOS開源代碼編譯報錯,報錯位置爲Test Target的源文件,我就挺奇怪我又沒作測試爲啥會編譯Test Target的源文件,以前的暴力解決方法是把Test Target直接刪掉。html
未免太暴力了點,刪除了還很差恢復,我想換一個方法來解決。首先就是要弄明白爲啥會編譯Test Target源文件。摸索了一下,找到了緣由:選擇Xcode左上角Simulator/Device左側的Scheme名,在下拉列表裏選擇Edit Scheme,隨後選擇Build選項,能夠看到裏面有Test Target,而且勾選了對應的Run選項。取消勾選Test Target的Run選項,再從新Build,就不會報錯了。ios
至於Test Target源文件中的代碼問題,之後再解決了。
app
關於Scheme、Target、Workspace的一些信息以下:ide
An Xcode scheme defines a collection of targets to build, a configuration to use when building, and a collection of tests to execute.
You can have as many schemes as you want, but only one can be active at a time. You can specify whether a scheme should be stored in a project—in which case it’s available in every workspace that includes that project, or in the workspace—in which case it’s available only in that workspace. When you select an active scheme, you also select a run destination (that is, the architecture of the hardware for which the products are built)測試
能夠看出Scheme和Targets能夠是一對一,也能夠是一對多的關係。同一時間只能有一個scheme是激活的。ui
A target specifies a product to build and contains the instructions for building the product from a set of files in a project or workspace. A target defines a single product; it organizes the inputs into the build system—the source files and instructions for processing those source files—required to build that product. Projects can contain one or more targets, each of which produces one product.
spa
A workspace is an Xcode document that groups projects and other documents so you can work on them together. A workspace can contain any number of Xcode projects, plus any other files you want to include. In addition to organizing all the files in each Xcode project, a workspace provides implicit and explicit relationships among the included projects and their targets.
.net
能夠看出一個workspace裏能夠包含多個Xcode project。code
使用Workspace的好處有:
1),擴展項目的可視域,便可以在多個項目之間跳轉,重構,一個項目能夠使用另外一個項目的輸 出。Workspace會負責各個Project之間提供各類相互依賴的關係;
2),多個項目之間共享Build目錄。htm
參考:
iOS:Xcode一些概念Target|Project|Build Setting|Workspace|Scheme[譯]Xcode Concepts
猿題庫iOS客戶端的技術細節(一):使用多target來構建大量類似App