Dependency Usage in Public Swift Projects

A look at Swift Package Manager usage, dependency analysis, and the Swift ecosystem in public Github repositories

Note: All results accurate as of January 21, 2020.

I’m a big fan of Swift, Apple’s programming language which was seen an explosion in growth since being introduced in 2014 and subsequently open-sourced a year later. Beyond iOS/macOS development, where Swift has really captured my attention is for web development. With Apple’s introduction of SwiftNIO, which is touted as “like Netty, but written for Swift.”, Swift developers were given the ability to easily begin doing network-based server/client development. Several additional frameworks have also sprung up over the years which are slowly but surely growing in popularity; see Kitura by IBM, Vapor and Perfect.

I’ve written about my experiences with a few of these in the past.

Recently while doing some research for Ochrona, I came across this blog post about the state of python dependency usage which was gathered using data from pypi. In particular, I thought that the graph of dependencies the author was able to generate was fascinating. This got me thinking about the state of Swift dependencies. If you’re familiar with swift mobile development you may have heard of some of its package managers such as CocoaPods or Carthage. These solutions have tried to grow to follow the Swift ecosystem as it’s evolved, but in 2018 Apple announced the Swift Package Manager, which at the time was primarily to support OS Swift projects, but was updated in 2019 to support iOS development as well. I’ve written in the past about publishing Swift packages.

Where things get interesting, is that unlike pypi or Maven Central, which are central package repositories, the Swift Package Manager has no central repository to pull from, and instead can import code from public (or private) Swift package repos. Swift Package Manager was aimed at making it easier to distribute software and share and use open-source Swift code. Since there is no single source of truth around Swift dependency usage, I decided to try to gather as much information as I could looking at the world’s largest repository of swift code, Github.

Note that the following finding should be taken with a grain of salt. You can find all of my code used to collect and analyze package usage here.

Total public Swift repos

There are upwards of 414,000 public swift repos on Github according to the UI search, however, the repository search API returns ~125k, my guess is that the actual number is closer to the latter.

Repos with a Package.swift file

There are roughly 30,800 public repos on Github that contain at least 1 Package.swift file. The actual number of Package.swift files is substantially larger than this, closer to 50k, however many of these are tutorials or examples that contain a large number of package.swift files.

Average size of a Package.swift file

Doing some analysis on all of the package.swift files collected for this, the average size of the publicly accessible package.swift files were 1.2 Kb.

Dependencies stats

Looking at all of the repos with a package.swift file, the mean number of dependencies used was 1.1, while the median was 0. When excluding repos without any dependencies, the mean became 2.31 with a median of 2, meaning that IF dependencies were included, they more often than not included more than one. One area where this stat may be misleading is that it doesn’t include the fully resolved dependencies for a swift package, rather just the explicitly required dependencies included in the package.swift file.

These numbers are in stark contrast to other languages like node, which on average utilizes ~35 npm packages per module. While npm is often known as being a dependency hellscape, I would guess that even fully-resolves dependency trees for the average swift package are still much small than this.

Most popular public repos

By star count, the most popular repos are:

By fork count, the most popular repos are:

* These counts include Swift repos that do not contain a package.swift file.

Most popular repos used as dependencies

The following is a list of the top 20 used dependencies.

Package.swift dependency graph

You can learn more about how I created this graph by checking out this repo. You can also play with an interactive version of the graph here — though note there may be a bit of lag due to the number of nodes and edges. The interactive graphs also don’t work great on mobile.

Swift dependency graph — interactive version -> https://beatsbears.github.io/vapor.html

Vapor related dependencies

The most interesting, and numerous of the dependencies used in package.swift files relate to the Vapor service-side Swift framework. To get a better look at these I decided to graph just the official vapor projects and all projects built using those projects. You can view and interactive version of this graph here or learn about how I made it here.

Vapor dependency graph — interactive version -> https://beatsbears.github.io/vapor.html

Apple-related Dependencies

Finally, I decided to do a similar graph just for projects using one of apple’s repos as a dependency. You can view and interactive version of this graph here. Since this one is so much smaller than the other graphs in terms of the number of nodes and edges, it’s a bit easier to play within the browser.

Apple dependency graph — interactive version -> https://beatsbears.github.io/apple.html

Conclusion

That’s it! A quick look into the world of Open-Source Swift dependency usage in public Github repos. If there are any questions you still have, or would like to add to this work, feel free to leave me a comment here or open an issue on my corresponding GitHub project.