I am trying to create a Xcode workspace which has multiple projects in it. I want to add different dependencies for each project. Let’s say I have MyApp (Master project), WebService (framework) and UIComponent (framework) projects. I wan’t to add Alamofire only to WebService project or I wan’t to add Lottie for only to UIComponent project.
MyWorkspace
|- MyApp
|- WebService
|-> Alamofire
|- UIComponent
|-> Lottie
The problem is, when I add WebService and UIComponent dependency to my MyApp project (via Linking Binaries from Xcode), it can access dependencies of my sub-projects. In other words MyApp project can access and import Alamofire and Lottie. Is there a way to prevent MyApp project can not import sub-projects dependencies?
I tried to achieve this using both Swift Package Manager and CocoaPods but no luck.
2
Answers
CocoaPods is fine, distinguish different target
With Swift Package Manager
You actually don’t need a workspace to do this. You could just use an Xcode Project. I am currently doing this for a project I’m working on.
Core is used in every package, Http in DataAccess, DataAccess in ApplicationServices, ApplicationServices in Presenters, and Presenters in the app.
To create a setup like this, open your workspace or Xcode project click file and create a new swift package. Save that package in your application’s directory and link it to the project or workspace you want to work in.
If you do this a few times you can start referencing the other local swift packages like this:
Then with a local package, we include it a little differently than a remote swift package. Click on the Project in the file navigation, select the app target, then under General in Frameworks, Libraries, and Embedded Content click the
+
button. You should be able to select the local packages you care about.If you need anything described more clearly let me know.