Swift Package Manager and Capacitor

As an iOS developer, I’ve always found Dependency management for iOS to be a chore. For the first four years of the iPhone platform, we didn’t have any options at all. That changed in September of 2011 with the creation and release of Cocoapods by Elon Durán. Written in Ruby, Cocoapods made it possible to properly manage your dependencies with a Podfile and a pod install
typed at the command line. At the time I’m writing this, Cocoapods has more than 962 thousand commits with over 105 thousand libraries available.
However, the release by Apple of Swift Package Manager (SPM) in 2015 marked the beginning of the end for our long-time package manager. And in August of 2024, after 13 years of being the top package manager, Cocoapods announced that they were entering maintenance mode. By November of 2024, they had announced that the Cocoapods Specs repository would become read-only on December 2, 2026.
What does that mean for you, as a Capacitor developer?
The good news is that starting with Capacitor 8, SPM is going to be a first-class citizen alongside Cocoapods. We plan to update our libraries on Cocoapods right up until December 2, 2026 when we will no longer be allowed to update them.
However, you cannot mix SPM and Cocoapods in one project. While all of the Ionic-maintained Capacitor plugins are supported for projects using SPM, 3rd party plugins will need to be updated before they can be used in an SPM Capacitor project. Cordova plugin support may be limited or may require some work to get everything working. We’re working our hardest to make this a seamless transition, so reach out by creating an issue if you run into any problems.
Application Development with Swift Package Manager
New projects provide the simplest way to get started. In fact, Capacitor 8, due to be released this fall, will default new projects to SPM dependency management. As soon as you run:
npx cap add ios
you’ll be ready to go. From there everything should work as you expect. The only real check you’ll need to make is to see if a plugin you want to use supports SPM instead of Cocoapods. If you want to continue using Cocoapods for the time being, override this by running:
npx cap add ios --packagemanager Cocoapods
when you add iOS to your Capacitor project.
If you have an existing project, there are a few more steps to migrate to SPM. We have a straightforward guide in our docs, Using SPM in an Existing Capacitor Project. The Capacitor CLI has a tool to assist you, npx cap swift-migration-assistant, along with some quick manual steps.
Getting your plugins ready for Swift Package Manager
If you develop Capacitor plugins, we created the capacitor-plugin-converter project to streamline this process. While this project is still under development it will eventually fully automate the conversion process.
Currently, if your plugin only uses Swift aside from the required Plugin.m
/ Plugin.h
files, our converter can be used to make the SPM conversion process easier. (This also works if you use [PluginName]Plugin.m
and [PluginName]Plugin.h
files)
Using the swift-syntax library, capacitor-plugin-converter will change your Plugin.swift file to match what the old CAP_PLUGIN
macros did. It will add the conformances, generate, move, and delete files to bring your plugin to SPM. A detailed description and instructions can be found in the Capacitor documentation.
However, If your plugin mixes Objective-C and Swift the automated tools will not work so manual conversion will be required. This is a limitation of Swift Package Manager as it does not allow mixing of Objective-C and Swift in the same target. One option is to rewrite all your Objective-C as Swift, which could take a while. Another option would be to manually split your work into two libraries. Detailed advice on how to do this will be coming to the blog and documentation soon, so stay tuned.
Closing
Capacitor 8 is well on its way, and we’re working hard to make sure that the end of Cocoapods causes as little disruption as possible. Hopefully, as SPM gains traction in the Capacitor community we can use its functionality to offer cool new features.