Swift Package Manager Nested Dependencies (Local Packages)

Hasancan Akgündüz
2 min readAug 8, 2021

--

This article will guide you through creating an example modularized project using Swift Package Manager(SPM). There will be two local swift packages and a main project which contains these packages. Both local packages have “swift-log” (a SPM package for logging)dependency hence the main project will contain nested dependencies.

MainProject
→ Package1 → swift-log
→ Package2 → swift-log

First let’s create Package1: File → New → Swift Package…

And then add swift-log as dependency to package:

Package1

Test if we can use swift-log library in Package1:

Test Package1

Package1 is ready. Create Package2 by following the exactly same steps.

Time to create MainProject. Simply create a new iOS App project. Now, this is important: Close both Package1 and Package2 Xcode window. Open the finder and drag Package1 and Package2 folders and drop into MainProject in Xcode. After this step, MainProject should look like this:

swift-log is automatically resolved and fetched. If you can not see the source files of Package1 or Package2, that means the Xcode window for these projects are still open, you need to close it and reopen MainProject.

To import the packages in MainProject, first we should link the libraries. Select project and then MainProject target. Click on Build Phases and add Package1 and Package2 libraries:

Now we are able to access the packages in our ViewController:

--

--

No responses yet