Xcode 工作区与嵌套项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11618407/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode Workspace vs Nested Projects
提问by mark
I don't understand the use of an Xcode workspace to organize projects with dependencies on one another. For instance I see a lot of developers create workspace structures that look like this:
我不明白使用 Xcode 工作区来组织相互依赖的项目。例如,我看到很多开发人员创建如下所示的工作区结构:
Workspace |-- App |-- A Common Library |-- Another Common Library
What benefit does this provide? If anyone opens the "App" project directly won't they be unable to actually build the app? They'd have to realize that a workspace exists with the necessary dependencies.
这提供了什么好处?如果有人直接打开“应用程序”项目,他们是否无法实际构建应用程序?他们必须意识到存在具有必要依赖项的工作区。
It seems to me like the better approach is to use nested projects like this:
在我看来,更好的方法是使用这样的嵌套项目:
App |-- Libraries | |-- A Common Library | |-- Another Common Library
Then no project exists that cannot be built. It also seems more in line with Git's idea of submodules.
那么不存在无法构建的项目。它似乎也更符合 Git 的子模块思想。
The only use I see for a workspace is to group common projects with no dependencies on one another. I'd like to hear other people's thoughts on this because I may be missing something.
我看到的工作区的唯一用途是将公共项目分组在一起,彼此之间没有依赖关系。我想听听其他人对此的看法,因为我可能遗漏了一些东西。
采纳答案by Mr. Berna
I use workspaces when I want to combine projects while also maintaining project independence.
当我想要组合项目同时保持项目独立性时,我会使用工作区。
An example where I use workspaces is series of tutorial projects that progress from very simple to more complex. Each project can function as a standalone project, but grouping them together in a workspace helps my organization of the overall project.
我使用工作区的一个例子是一系列从非常简单到更复杂的教程项目。每个项目都可以作为一个独立的项目运行,但将它们组合在一个工作区中有助于我组织整个项目。
In another instance I have an app developed for a client. The app works as both a standalone app and a module in the overall project. The independent project can build the standalone app. The other app uses a workspace that includes two projects. The module version of the app is built from a special scheme, and this combined app doesn't build without using the workspace.
在另一个例子中,我有一个为客户开发的应用程序。该应用程序既是一个独立的应用程序,又是整个项目中的一个模块。独立项目可以构建独立的应用程序。另一个应用程序使用包含两个项目的工作区。该应用程序的模块版本是根据特殊方案构建的,并且此组合应用程序不会在不使用工作区的情况下构建。
One twist with the two above situations is where the build folder is stored. I have to change the Xcode preference to put the build products into unique folders for the group of tutorial projects, use a common build folder for the module within the other app setup.
上述两种情况的一个转折是构建文件夹的存储位置。我必须更改 Xcode 首选项以将构建产品放入教程项目组的唯一文件夹中,在其他应用程序设置中为模块使用通用构建文件夹。
In other circumstances I have plenty of projects with embedded projects. In these situations the library projects are stable. I don't attempt further development of the library projects so they are just another resource for the project. I find it easier to work where my file system organization of project resources somewhat reflects the organization of my Xcode project. So these library projects are copied into the main project's file hierarchy. It would make sense to use workspaces if I was developing the libraries and using them in multiple projects. For expedience I frequently don't bother.
在其他情况下,我有很多带有嵌入式项目的项目。在这些情况下,库项目是稳定的。我不会尝试进一步开发图书馆项目,因此它们只是该项目的另一种资源。我发现在我的项目资源文件系统组织某种程度上反映了我的 Xcode 项目组织的情况下,工作更容易。所以这些库项目被复制到主项目的文件层次结构中。如果我正在开发库并在多个项目中使用它们,那么使用工作区是有意义的。为方便起见,我经常不打扰。
Sometimes I even combine workspaces with projects containing embedded projects.
有时我什至将工作区与包含嵌入式项目的项目结合起来。
So my opinion is that both organizational tools, embedded projects and workspaces, have their merits and problems. I choose to use one or the other (or a combination) depending upon the particular circumstances.
所以我的观点是,组织工具、嵌入式项目和工作区都有其优点和问题。我根据特定情况选择使用其中一种(或组合)。
回答by Patricia
We added nested projects into the Main project's Frameworks, so we could "include" them into the .framework product.
我们将嵌套项目添加到主项目的框架中,因此我们可以将它们“包含”到 .framework 产品中。
Main
|-- Main
|-- MainTests
|-- Frameworks
| |-- CommonLibrary.xcodeproj
| |-- AnotherCommonLibrary.xcodeproj
| |-- UIKit.framework
| |-- Foundation.framework
| |-- CoreFoundation.framework
|-- Products
See this Great Tutorial by Jeff Verkoeyenfor adding Universal Frameworks to a project. It not easy, at first, but keep working on it and you'll get the hang of it.
请参阅Jeff Verkoeyen 的这个伟大的教程,将通用框架添加到项目中。一开始并不容易,但继续努力,你就会掌握它的窍门。