简体   繁体   English

XCode工作区中的代码库项目与目标的比较

[英]Projects Vs Targets for a codebase in an XCode Workspace

The XCode documentation on the concepts of Targets and Projects are helpful, but still I am not certain on the best practices to use in my situation. 有关目标项目概念的XCode文档很有帮助,但是我仍然不确定在我的情况下可以使用的最佳实践。

I have an existing codebase (used for Windows as well as iOS) in a single SVN repository, which has just been refactored from one single test application into a central library and an application. 我在一个SVN信息库中有一个现有的代码库(用于Windows和iOS),该代码库刚刚从一个测试应用程序重构为一个中央库和一个应用程序。 The idea is more applications will use this central library over time. 想法是随着时间的推移,更多的应用程序将使用此中央库。

An XCode project maps one set of source files to one or more targets, so I could have a single project for my whole codebase and one target for the library and one for each app. 一个XCode项目将一组源文件映射到一个或多个目标,因此我可以为我的整个代码库提供一个项目,为库提供一个目标,为每个应用程序提供一个目标。 However each app will obviously have its own code, so it seems a bit clunky to throw all the source into a single project this way. 但是,每个应用程序显然都有其自己的代码,因此以这种方式将所有源代码放入单个项目中似乎有些笨拙。

Alternatively I could have a workspace with multiple projects, each having a single target. 或者,我可以有一个包含多个项目的工作区,每个项目都有一个目标。 This is much more how I have things set up for the Windows build, where a Visual Studio solution corresponds to the Xcode workspace, and a VC++ project would map neatly against how XCode projects are organised. 这是我为Windows构建设置的方式的更多内容,在Windows构建中,Visual Studio解决方案对应于Xcode工作区,而VC ++项目将与XCode项目的组织方式巧妙地映射。

But are there 'normal' / expected ways to do things in this kind of situation, some unofficial standards I should try to follow so other developers don't get confused? 但是在这种情况下是否有“正常” /预期的方式来做事,我应该尝试遵循一些非正式的标准,以免其他开发人员感到困惑?

Targets nowadays are used to build dependencies and separate builds within a project. 如今,目标用于构建依赖关系并在项目​​内分离构建。 You'll see it being used mainly for unit testing. 您会看到它主要用于单元测试。 Occasionally, you might have different binaries available to different processors or operating systems, but this is a rarity in today's app store world. 有时候,您可能有不同的二进制文件可用于不同的处理器或操作系统,但这在当今的应用商店世界中很少见。

Generally, you'd have one project for each executable. 通常,每个可执行文件都有一个项目。 This allows it to be worked on independently and compiled separately without interfering with each other. 这使得它可以独立工作,并且可以独立编译而不会互相干扰。

You can include projects within projects, which allows you to work on them independently and set up dependencies for them. 您可以在项目中包含项目,这使您可以独立处理它们并为其建立依赖关系。 You can set up a project to build a sub-project and deposit it's executable in a location for your project to link to. 您可以设置一个项目以构建一个子项目,并将其可执行文件存放在项目可以链接到的位置。

I would say for your situation, make a library project with executable and testing targets. 对于您的情况,我想说一个具有可执行文件和测试目标的库项目。 Then include that project in other projects and you can link to or move the files to your other project's location. 然后将该项目包含在其他项目中,您可以链接到文件或将文件移动到其他项目的位置。 Here's the gist of how to do it. 这是如何做的要点。

I know you don't mention them, but workspaces were basically added to allow you to have multiple projects open in a single window. 我知道您没有提到它们,但基本上已添加了工作区,以使您可以在单个窗口中打开多个项目。 You can have all your test applications and reference code available without them compiling in the background as well. 您可以拥有所有测试应用程序和参考代码,而无需在后台进行编译。 I find it super handy. 我觉得它非常方便。

The key difference is that each target is in exactly one project, but one project can be a part of many workspaces. 关键区别在于,每个目标仅在一个项目中,但是一个项目可以是许多工作空间的一部分。 This lets you have projects Lib, AppA, and AppB, and then WorkspaceA = [AppA, Lib] and WorkspaceB = [AppB, Lib], so that developers working on AppA don't have to load stuff related to AppB. 这样一来,您就可以拥有项目Lib,AppA和AppB,然后再选择WorkspaceA = [AppA,Lib]和WorkspaceB = [AppB,Lib],这样开发AppA的开发人员就不必加载与AppB相关的内容。 As a general recommendation it's a good idea to create projects for things that you might want to share independently. 作为一般建议,最好为您可能希望独立共享的内容创建项目。

When I share code between one or more projects (be it Xcode or another IDE), I typically compile the shared parts into a binary and then link it to the code specific projects. 当我在一个或多个项目(Xcode或另一个IDE)之间共享代码时,通常将共享部分编译为二进制文件,然后将其链接到特定于代码的项目。

In your setup, something like an Xcode project just to compile a dylib from shared C++ files, and then a main Xcode project that links with this dylib. 在您的设置中,类似一个Xcode项目,只是从共享的C ++文件编译一个dylib,然后是一个与该dylib链接的主Xcode项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 具有多个项目的工作区或具有多个目标的一个项目? - Workspace with multiple projects or one project with multiple targets? 我可以在xCode工作区上运行2个单独的项目吗? - Can I run 2 separate projects on xCode workspace? 2个工作区中的2个项目xcode(代码共享) - 2 Projects in the same workspace xcode (code share) 具有多个项目和Coca Pod设置的Xcode工作区 - Xcode Workspace with Multiple Projects and Coca Pods Setup 来自一个代码库的多个应用程序 - Xcode 中的多个项目或目标? - Multiple apps from one code base - multiple projects or targets in Xcode? 具有2个项目的xcode工作区。 如何在项目2中的项目1中创建对象? - xcode workspace with 2 projects. how to create object from project 1 in project 2? 如何将Crittercism集成到具有多个子项目的Xcode工作区中? - How to integrate Crittercism into an Xcode workspace with multiple sub-projects? Xcode共享运行脚本在工作区中的项目之间构建阶段 - Xcode share run script build phase between projects in a workspace 无法在工作区xcode7中的两个项目之间导入文件 - Cannot import files between two projects in a workspace xcode7 Xcode:工作区中的所有项目都可以使用文件吗? - Xcode: Is it possible to have files available to all projects within a workspace?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM