简体   繁体   English

如何在工作区中的两个xcode项目之间共享文件?

[英]How to share files between two xcode projects in workspace?

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 提前致谢

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 . 假设您要在Project1Project2之间共享常量,并且这些常量在SharedConstants.swift文件中定义,该文件在Project1定义。
In order to be used in Project2 , it must be compiled there. 为了在Project2 ,必须在那里编译它。

Thus, activate in the project navigator Project2 , select the target and open the Build Phases tab. 因此,在项目导航器Project2激活,选择目标并打开Build Phases选项卡。
Open there Compile Sources by tapping the little triangle left. 打开那里通过点击左边的小三角形Compile Sources

Tap the + button below the listed sources for this target. 点按此目标列出的来源下方的+按钮。 This will show you a list of files of Project2 . 这将显示Project2的文件列表。 There you cannot select your shared constants, because they do not belong to this project. 在那里,您无法选择共享常量,因为它们不属于此项目。
However left bottom is a button Add other… 但是左下角是一个按钮Add other…
Tapping it will open a standard file selection window where you can select SharedConstants.swift from Project1 . 点击它将打开一个标准文件选择窗口,您可以从Project1选择SharedConstants.swift

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 copy of SharedConstants.swift would be used in Project2 , and any changes that you make in Project1 would not be visible in Project2 . 如果要检查它,将在Project2使用SharedConstants.swift副本 ,并且您在Project1所做的任何更改都不会在Project2可见。 Instead, it you uncheck it, only a reference to SharedConstants.swift in Project1 would be used in Project2 , and any changes will affect both projects. 相反,它取消选中它,只是一个参考 SharedConstants.swiftProject1将用于Project2 ,任何变化都将影响项目。

To share the files you can probably use the bundles 要共享文件,您可以使用捆绑包

Targets are manipulated with Schemes in 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: 您会在停止按钮下方看到一个小三角形,表示您可以长按它以选择应终止哪个操作: Xcode中

You can switch the console with the popover at the Debug area where you see the target name and icon - that's a button. 您可以在调试区域使用弹出窗口切换控制台,您可以在其中看到目标名称和图标 - 这是一个按钮。

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? 我应该如何在Xcode工作区中跨项目管理依赖项?

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM