Xcode 项目与 Xcode 工作区 - 差异 [英] Xcode Project vs. Xcode Workspace - Differences

查看:38
本文介绍了Xcode 项目与 Xcode 工作区 - 差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解 iOS 的整个生态系统是如何运作的.
到目前为止,我可以为我的大部分问题找到答案(相信我,已经有很多答案了),但对于这个问题,似乎还没有明确的答案.

I am trying to understand how the whole ecosystem of iOS works.
Until now, I could find an answer for most of my question (and trust me, there have been a lots of them), but for this one, there seems to be no clear answer yet.

XcodeProject 和 XcodeWorkspace 文件有什么区别?

  1. 两者有什么区别?
  2. 他们负责什么?
  3. 在团队/单独开发应用程序时,我应该与他们中的哪一位合作?
  4. 关于这两个文件,我还有什么需要注意的吗?

推荐答案

我认为关于项目结构,您需要了解三个关键项目:目标项目、和工作区.目标详细指定了产品/二进制文件(即应用程序或库)的构建方式.它们包括构建设置,例如编译器和链接器标志,并定义哪些文件(源代码和资源)实际上属于产品.当您构建/运行时,您总是选择一个特定的目标.

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.

您可能有几个共享代码和资源的目标.这些不同的目标可能是应用程序的略有不同版本(iPad/iPhone、不同品牌,...)或自然需要访问与应用程序相同的源文件的测试用例.所有这些相关目标都可以归入一个项目.虽然项目包含来自其所有目标的文件,但每个目标都会选择自己的相关文件子集.构建设置也是如此:您可以在项目中定义默认的项目范围的设置,但如果您的目标之一需要不同的设置,您始终可以在那里覆盖它们:

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 override them there:

所有目标都继承的共享项目设置,除非它们覆盖它

Shared project settings that all targets inherit, unless they override it

具体目标设置:PSE iPhone覆盖项目的Base SDK设置

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

在 Xcode 中,你总是打开项目(或工作区,但不是目标),它包含的所有目标都可以构建/运行,但没有构建项目的方法/定义,所以每个项目至少需要一个目标以便不仅仅是文件和设置的集合.

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

在很多情况下,您只需要项目即可.如果您有从源代码构建的依赖项,则可以将其嵌入为子项目.子项目可以单独打开,也可以在其超级项目中打开.

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 是一个子项目

如果将子项目的目标之一添加到超级项目的依赖项中,则子项目将自动构建,除非它保持不变.这里的优点是您可以在同一个 Xcode 窗口中编辑项目和依赖项中的文件,并且在构建/运行时,您可以从项目及其子项目的目标中进行选择:

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:

但是,如果您的库(子项目)被各种其他项目(或准确地说是它们的目标)使用,则将其置于相同的层次结构级别是有意义的——这就是工作区 是为了.工作区包含和管理项目,它直接包含的所有项目(即,不是它们的子项目)都在同一级别上,它们的目标可以相互依赖(项目的目标可以依赖于子项目的目标,反之则不然).

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).

工作区结构

在此示例中,两个应用程序(AnotherApplication/ProjectStructureExample)都可以引用 demoLib 项目的目标.这也可以通过将 demoLib 项目作为子项目包含在其他两个项目中(仅作为参考,因此无需重复),但如果您有很多交叉依赖项,工作区会产生更多感觉.如果您打开一个工作区,您可以在构建/运行时从所有项目的目标中进行选择.

In this example, both apps (AnotherApplication / ProjectStructureExample) can reference the demoLib project’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.

您仍然可以单独打开您的项目文件,但它们的目标可能无法构建,因为 Xcode 无法解析依赖项,除非您打开工作区文件.工作区为您提供与子项目相同的好处:一旦依赖项发生变化,Xcode 将重建它以确保它是最新的(尽管我遇到了一些问题,但它似乎不能可靠地工作).

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).

您的问题简述:

1) 项目包含文件(代码/资源)、设置以及从这些文件和设置构建产品的目标.工作区包含可以相互引用的项目.

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) 两者都负责构建您的整个项目,但级别不同.

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

3) 我认为项目在大多数情况下就足够了.除非有特定原因,否则不要使用工作区.此外,您以后可以随时将项目嵌入到工作区中.

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) 我认为这就是上面的文字是为了……

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

对 3) 有一个说明:CocoaPods,它会自动为您处理 3rd 方库,使用工作区.因此,当您使用 CocoaPods(很多人都这样做)时,您也必须使用它们.

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).

这篇关于Xcode 项目与 Xcode 工作区 - 差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆