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.