如何在工作区中的两个 xcode 项目之间共享文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11947133/
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
How to share files between two xcode projects in workspace?
提问by Shreya P
I learnt about Xcode workspace .I know how to share the static library but i want to share the files between two xcode projects in workspace and is it possible to run multiple targets at a time?Can you provide me the information of how to do this.
我了解了 Xcode 工作区。我知道如何共享静态库,但我想在工作区中的两个 xcode 项目之间共享文件,是否可以一次运行多个目标?您能否提供有关如何执行此操作的信息.
Thanks in advance
提前致谢
回答by Reinhard M?nner
Sharing files between projects in the same workspace is easy, even if the projects are on the same level (no subprojects):
即使项目在同一级别(没有子项目),在同一工作区中的项目之间共享文件也很容易:
Assume you want to share constants between Project1
and Project2
, and these constants are defined in a file SharedConstants.swift
, which is defined in Project1
.
In order to be used in Project2
, it must be compiled there.
假设您要在Project1
和之间共享常量Project2
,并且这些常量定义在一个文件中SharedConstants.swift
,该文件定义在Project1
.
为了在 中使用Project2
,它必须在那里编译。
Thus, activate in the project navigator Project2
, select the target and open the Build Phases
tab.
Open there Compile Sources
by tapping the little triangle left.
因此,在项目导航器中激活Project2
,选择目标并打开Build Phases
选项卡。通过点击左侧的小三角形
打开那里Compile Sources
。
Tap the +
button below the listed sources for this target. This will show you a list of files of Project2
. There you cannot select your shared constants, because they do not belong to this project.
However left bottom is a button Add other…
Tapping it will open a standard file selection window where you can select SharedConstants.swift
from Project1
.
点击+
此目标列出的来源下方的按钮。这将向您显示Project2
. 在那里你不能选择你的共享常量,因为它们不属于这个项目。
然而左下方是一个按钮,Add other…
轻按它会打开一个标准的文件选择窗口,在这里你可以选择SharedConstants.swift
从Project1
。
After tapping Open
, a 2nd window opens with a Destination: Copy items if needed
checkbox.
点击 后Open
,会打开一个带有Destination: Copy items if needed
复选框的第二个窗口。
Important: Do not check this box!
重要提示:请勿选中此框!
If you would check it, a copyof SharedConstants.swift
would be used in Project2
, and any changes that you make in Project1
would not be visible in Project2
. Instead, it you uncheck it, only a referenceto SharedConstants.swift
in Project1
would be used in Project2
, and any changes will affect both projects.
如果你想检查一下,一个副本的SharedConstants.swift
会中使用Project2
,而且任何更改您在Project1
将不可见Project2
。相反,如果您取消选中它,则只会在 in中使用对in的引用,并且任何更改都会影响两个项目。SharedConstants.swift
Project1
Project2
回答by A-Live
To share the files you can probably use the bundles
要共享文件,您可能可以使用捆绑包
Targets are manipulated with Schemesin Xcode 4, you can launch several targets in the same time if you select the different destinations (with OS X you can probably have the same destination :) )
目标在 Xcode 4 中使用Schemes进行操作,如果您选择不同的目标,您可以同时启动多个目标(在 OS X 中,您可能有相同的目标:))
You'll see a little triangle below the stop button indicating that you can long-press it to select which operation should be terminated:
您会在停止按钮下方看到一个小三角形,表示您可以长按它来选择应终止哪个操作:
You can switch the console with the popover at the Debug area where you see the target name and icon - that's a button.
您可以在 Debug 区域使用弹出窗口切换控制台,您可以在其中看到目标名称和图标 - 这是一个按钮。
回答by occulus
You can drag Xcode projects into other Xcode projects to nest them.
您可以将 Xcode 项目拖动到其他 Xcode 项目中以嵌套它们。
More info here:
更多信息在这里:
How should I manage dependencies across projects in an Xcode workspace?