Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

Thanks in advance

like image 868
Shreya P Avatar asked Aug 14 '12 06:08

Shreya P


People also ask

How do I integrate one project to another file in Xcode?

You can just drag-and-drop any xcode-project file (*. xcodeproj) into the project navigation pane of your desired parent-project. You then may need to add target dependencies, depending on your needs.

How do I add an existing Xcode project to a workspace?

In the Project navigator, Control-click in the empty space and choose Add Files to “workspaceName”. In the sheet that appears, select an Xcode project (a file with a . xcodeproj filename extension). Click Add to add the project to the workspace.

Can you share an Xcode project?

To do that, right-click on the Remotes folder that is below the project folder on the left pane. Select your GitHub account (or add your GitHub account if you haven't done that already) and complete other details about your new remote. Now you are ready to start sharing your code with teammates.


1 Answers

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.

like image 160
Reinhard Männer Avatar answered Oct 25 '22 02:10

Reinhard Männer