I am looking for a way to add multiple SPM packages to an Xcode project (similar to how cocoapods works using it’s podfile
and calling pod install
)
I know I can manually go to File
->Add Package Dependencies...
to manually add one package at a time.
When building a SPM package I can add dependencies through the Package.swift
file. I tried adding a Package.swift
to a regular Xcode project but there seems to be no way for Xcode to used that file when working with iOS projects. There also doesn’t appear to be a command for Xcode’s command line build tools to update an Xcode project using a Package.swift
file?
Is there any other way for me to add SPM packages to an iOS Xcode project?
- Added a
Package.swift
(expected Xcode to read dependencies as it does when creating a Swift Package) - Searched documentation for Xcode command line tools (expected to find a command for adding a package to an Xcode project)
2
Answers
I was also facing the same problem. I switched to Tuist because of both the ability to install more than one package at the same time and the compilation time. If you want, take a look at the temp files, I hope it will be useful for you.
Github: https://github.com/tuist/tuist
I was very frustrated by SPM not supporting command line editing of
Package.swift
files (yet). I created clspm, a tool for working with SPM packages through the command line.The tool creates either a CSV or JSON file that lists all the dependencies already in your project. In your project directory call
The file it creates is called
spmfile
and by default will get created in your project directory. (If you don’t want any trace of this package manager in your repo you can pass in an outside directory and file name with--spmfile <FILE_DIR>
)Add the names of dependencies you’d like to use to the
spmfile
and callSince you have used cocoapods before this should all be pretty familiar.
(If your
spmfile
lives outside of your project directory pass in the directory and file name from yourinit
call with--spmfile <FILE_DIR>
)If this is the first time you are using those dependencies the tool will ask you for either a GitHub user name or the url of the repo. If you create other packages it remembers the repo locations (
~/.swiftclpm/dependencies
) andinstall
runs without interruption.Some extra info you didn’t ask about:
install
with the-l
option, followed by all the package names you’d like to work on locally. Callinginstall
again switches it back to remote implementations.to quickly create a local package from an Xcode project group. It creates the package and adds it to your project.