How to share files between two xcode projects in workspace?

8.5k views Asked by At

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.

Thanks in advance

3

There are 3 answers

2
A-Live On

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

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.

0
occulus On

You can drag Xcode projects into other Xcode projects to nest them.

More info here:

How should I manage dependencies across projects in an Xcode workspace?

1
Reinhard Männer On

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.

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.

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.

After tapping Open, a 2nd window opens with a Destination: Copy items if needed checkbox.

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