Swift Package Manager is a fantastic tool for managing dependencies, and over the years, Xcode support for SwiftPM has improved, streamlining the development workflow.

In Xcode 13, discovering and managing third-party Swift packages became a little easier with the introduction of Swift Package Collections (add link).

A Package Collection is a JSON file that describes a curated list of packages. The collection can be shared directly or online. It can also be signed to prevent tampering. This can be a great way to share dependencies across an organization or make frequently used packages more accessible.

Fix-it example in Xcode

Xcode is pre-configured with a single Package Collection published by Apple. Adding an import statement for one of the packages in this collection results in a fix-it prompt to add the dependency to the project. Adding new collections can enable this same fix-it for other Swift Packages.

The Swift Package Index maintained by Dave Verwer and Sven A. Schmidt makes it easy to find Swift Packages as well as Package Collections.

Add Package Collection in Xcode

A great third-party example is the open-source libraries authored by the folks at Pointfree. Pointfree publishes a number of fantastic utilities for writing code that is both testable and ergonomic.

Steps to add a collection:

  1. Within Xcode, click File > Add Packages…
  2. Under Package Dependencies, click the +
  3. In the bottom left corner of the package browser, click the +_ and select Add Package Collection…
  4. Paste the URL to the Package Collection
  5. Confirm by clicking Add Collection
Add Package Collection in Xcode

Once added, it is easy for Xcode to find and import your favorite packages.

If you try to import a module that isn’t already a dependency of a project, Xcode will give you a warning. But if the package is part of a package collection that is registered with Xcode, then Xcode will provide a fix-it that will automatically add the dependency to the project.

Add package collection from the command line

Package Collections can also be added to SwiftPM and made available in Xcode from the command line.

$ swift package-collection add https://swiftpackageindex.com/pointfreeco/collection.json

Package Collections aren’t going to save you hours of development time, but they will make your favorite packages more accessible while staying in the editor flow.

Related Articles

Creating Swift Package Collections

Swift Package Collections is a new feature in SwiftPM that allows you to group multiple packages together and distribute them as a single unit. This is useful for situations where you want to share a set of related packages with others, or for organizing your own packages for internal use. In this tutorial, we will walk through the process of creating a Swift Package Collection and using it in a project.

Top 16 Resources for Leveling Up Your Swift Development Skills in 2023

One of the things I love about software development is that there is always more to learn. This is especially true as a Swift developer with Apple releasing new versions of tools and frameworks every year, in addition to an endless number of open-source projects. Fortunately, the Swift community is also good about sharing this knowledge and experience to help each other grow. As a result, there is a lot of great content to choose from to improve your Swift development skills.