
Don’t get me wrong. I love Cocoapods. But it’s time to move on, for the times they are a-changin’
Apple Announced Xcode support for Swift Package Manager (SPM) on Xcode 11. However it’s undeniable that the vast majority of iOS’s rich Open Source dependencies are distributed through other dependency managers like Cocoapods or Carthage rather than the now “official” SPM.
Although this gist shows us that it is still possible to combine them, I find that inconvenient since it feels somewhat redundant.
To keep this really down to earth, we are going to use a tiny Pod of mine: NotificationBubbles.
I will be pointing out certain commits on my repo that will illustrate the changes I had to do. Also, you will be able to see what mistakes I’ve made and how I fixed them, of course.
First, it’s important to know that we are going to adapt our Pod’s folder structure so it suits the SPM folder structure. To achieve this we will generate the package structure inside our Pod by running
Step 1: swift package init
Warning: SPM will take whatever folder name the command is ran on as the project name. In this case I made sure that I’ve cloned my existing git repo inside a folder named ‘NotificationBubbles’
This commit will show you the changes involved on the package initialization, plus a “pod install”.
Up to now we have an empty package. So we need to start moving our source files where the SPM can locate them
Step 2: Move your sources to the corresponding folders

I moved all my source code to the Sources folder and did the same with the test files. This will break my podspec file, so I need to update it so Cocoapods finds the sources too. Fortunately this is pretty straight forward.
Step 3: reflect new folder structure in podspec file. Move source files to their new destination.

This commit will tell you the changes I did to achieve this. Don’t forget to commit all the actions to your repo, otherwise you will have to delete the copied files separately like I had to in this commit
Step 4: Do a ‘pod install’ in your existing Example project and check your pod works
You should run all your tests and verify the integrity of your beloved project. Also, don’t forget to bump up your podspec version.
Next step will be: Publishing your Swift Package to the world
Step 5: Tag your package’s version. in my case v1.0.0
And that’s pretty much it. Now we have to test it the Swift Package version of it by adding it to a test project.
Adding Swift Package Dependency on Xcode 11 (beta)
Xcode 11 includes SPM out of the box. To import a dependency, you just need to click here

Then put your dependency’s URL. In this case, https://github.com/pacu/NotificationBubbles.git

Then nail it to the version you want your project to depend on. Xcode will get the tags from the repo and suggest one for you.

Set that dependency to the target of choice

And that’s all. Build and test.
Adding Swift Package Dependency on Xcode 10
There’s a really nice blog post that tells us how to create an Xcode 10 project that uses Swift Package Manager below.
More information
If you are interested in creating a Swift Package from scratch, visit this awesome article
Also, don’t forget to visit the official documentation!
Thanks for reading!