project target workspace

I think there are three key items you need to understand regarding project structure: Targets, projects, and workspaces. Targets specify in detail how a product/binary (i.e., an application or library) is built. They include build settings, such as compiler and linker flags, and they define which files (source code and resources) actually belong to a product. When you build/run, you always select one specific target.

It is likely that you have a few targets that share code and resources. These different targets can be slightly different versions of an app (iPad/iPhone, different brandings,…) or test cases that naturally need to access the same source files as the app. All these related targets can be grouped in a project. While the project contains the files from all its targets, each target picks its own subset of relevant files. The same goes for build settings: You can define default project-wide settings in the project, but if one of your targets needs different settings, you can always overwrite them there:

Shared project settings that all targets inherit, unless they overwrite itShared project settings that all targets inherit, unless they overwrite it

Concrete target settings: PSE iPhone overwrites the project’s Base SDK settingConcrete target settings: PSE iPhone overwrites the project’s Base SDK setting

In Xcode, you always open projects (or workspaces, but not targets), and all the targets it contains can be built/run, but there’s no way/definition of building a project, so every project needs at least one target in order to be more than just a collection of files and settings.

Select one of the project’s targets to run Select one of the project’s targets to run

In a lot of cases, projects are all you need. If you have a dependency that you build from source, you can embed it as a subproject. Subprojects can be opened separately or within their super project.

demoLib is a subprojec demoLib is a subproject

If you add one of the subproject’s targets to the super project’s dependencies, the subproject will be automatically built unless it has remained unchanged. The advantage here is that you can edit files from both your project and your dependencies in the same Xcode window, and when you build/run, you can select from the project’s and its subprojects’ targets:

Running targets from a subproject

If, however, your library (the subproject) is used by a variety of other projects (or their targets, to be precise), it makes sense to put it on the same hierarchy level – that’s what workspaces are for. Workspaces contain and manage projects, and all the projects it includes directly (i.e., not their subprojects) are on the same level and their targets can depend on each other (projects’ targets can depend on subprojects’ targets, but not vice versa).

Workspace structure Workspace structure

In this example, both apps (AnotherApplication / ProjectStructureExample) can reference the demoLibproject’s targets. This would also be possible by including the demoLib project in both other projects as a subproject (which is a reference only, so no duplication necessary), but if you have lots of cross-dependencies, workspaces make more sense. If you open a workspace, you can choose from all projects’ targets when building/running.

Running targets from a workspace

You can still open your project files separately, but it is likely their targets won’t build because Xcode cannot resolve the dependencies unless you open the workspace file. Workspaces give you the same benefit as subprojects: Once a dependency changes, Xcode will rebuild it to make sure it’s up-to-date (although I have had some issues with that, it doesn’t seem to work reliably).

Your questions in a nutshell:

1) Projects contain files (code/resouces), settings, and targets that build products from those files and settings. Workspaces contain projects which can reference each other.

2) Both are responsible for structuring your overall project, but on different levels.

3) I think projects are sufficient in most cases. Don’t use workspaces unless there’s a specific reason. Plus, you can always embed your project in a workspace later.

4) I think that’s what the above text is for…

There’s one remark for 3): CocoaPods, which automatically handles 3rd party libraries for you, uses workspaces. Therefore, you have to use them, too, when you use CocoaPods (which a lot of people do).

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Xcodeproject 指的是单个应用程序或者库的开发工程,它包含了所有的源代码、资源文件、配置等。workspace 则是一个工程集合,它可以包含多个 project,常用于在同一个界面管理多个相关的工程。 ### 回答2: Xcode是苹果公司开发的一款集成开发环境(IDE),用于开发iOS、iPadOS、macOS和watchOS应用程序。在Xcode,有两个重要的概念:project(项目)和workspace(工作区)。 1. Project(项目):一个project代表一个独立的应用程序或库。它包含了应用程序的源代码文件、资源文件、配置信息等等。一个project可以包含多个target,每个target代表了一个不同的构建版本,比如开发版本、上线版本等等。项目的修改仅对该项目内部生效。 2. Workspace(工作区):工作区是用于组织多个相关的项目的容器。它可以包含一个或多个project,并且支持在这些project之间共享文件和配置。通过使用工作区,我们可以在一个集成的界面同时打开多个项目,方便进行跨项目的操作和协同开发。在工作区可以添加或移除项目,也可以方便地在项目之间进行导航和搜索。 简而言之,project是用于管理单个应用或库的文件、设置和构建配置,而workspace是用于管理多个相关项目的容器,方便在一个集成的开发环境进行跨项目的协同开发和操作。同时,工作区还提供了更方便的导航和搜索功能,使得开发者可以更高效地处理多个项目。 ### 回答3: Xcodeproject(项目)和workspace(工作区)是两种不同的概念和功能。具体区别如下: 1. Project(项目)是指一个完整的开发项目,包含了所有用于构建和管理应用程序的资源文件,比如源代码、图像、音频和其他资产。一个项目通常对应一个应用程序或一个框架。 2. Workspace(工作区)是指一种用于组织和管理多个相关项目的容器。工作区使得开发者可以在同一个Xcode窗口同时打开、编辑和构建多个项目,方便协同开发和项目组织。 具体区别如下: 1. 组织结构:Project(项目)是一个独立的实体,包含了项目所需的所有资源文件和设置。而Workspace(工作区)则是一个容器,可以包含多个相关的项目。 2. 编译和构建:在XcodeProject可以被编译和构建成最终的应用程序或框架;而Workspace本身不能被编译和构建,它只是用于管理和组织项目。 3. 依赖管理:Project(项目)可以指定依赖关系,引入其他项目或框架作为依赖;而Workspace可以集成多个项目,并自动管理它们之间的依赖关系。 4. 工作流程:在一个项目,开发者通常会专注于一个具体的任务,比如编写代码、调试或构建。而在Workspace,开发者可以同时处理多个项目,方便协同开发和管理项目之间的依赖关系。 总之,Project(项目)是一个独立的开发单位,包含了项目所需的资源和设置;而Workspace(工作区)是一个用于组织和管理多个项目的容器。使用Workspace可以方便地进行项目协同开发和管理项目依赖关系。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值