Member-only story

Use Swift Package Manager to Add Dependencies

SPM + Xcode + THAT GREAT PACKAGE

Steven Curtis
4 min readJun 19, 2020
Photo by Katherine Gu on Unsplash

If you have reusable modules you might already use Swift Package Manager (SPM) to manage these dependencies for you. In this article, we will use SPM to fetch and use third-party code in our project.

excellent

Difficulty: **Beginner** | Easy | Normal | Challenging

This article has been developed using Xcode 11.4.1, and Swift 5.2.2

What are dependencies anyway?

Something you depend on. Now, come on, even I can do better than that.

Imagine you want to use an external library for something a little tricky, like networking.

We can call that library Alamofire, and indeed many programmers use this for their projects as it avoids using their own network library and can feel secure that the library is already in use and well-tested in a variety of contexts.

Now there is an in-built problem here. If the third-party dependency has a bug in it and they fix it; do you want to use that new version with the fix (probably) and do you want to use that new version with a host of new features (umm, probably — if it doesn’t break the code that I’m working on). Which means that dragging files into your project is a quite immature and unhelpful way of managing depenencies in a larger project. Therefore *package managers* have been developed to help us out.

Package Managers

Swift Package Manager isn’t the only option for managing dependencies and giving us our desired third-party libarary (and version of the said libarary).

There are several other Package Managers you may have heard of — CocoaPods and Cathage

Find those dependencies

With so many third-party libaries avaliable for Swift, how do you pick the right one for you? You’ll need to consider (amongst other questions) the following:

  • support (updates etc.)
  • compatibility with your current Swift version
  • platform support of the libarary

--

--

No responses yet

Write a response