有几回遇到从网上下载到的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