Migrate Your iOS Project From CocoaPods To Swift Package Manager
Tags: ios, beginners, tutorial, swift
Published: 2020-11-18 17:41:38

---
title: Migrate Your iOS Project From CocoaPods To Swift Package Manager
published: true
description: 
tags: iOS, Beginners, Tutorial, Swift
cover_image: https://i.imgur.com/KqSP9y3.png
canonical_url: https://getstream.io/blog/migrate-cocoapods-to-spm/
---

As of Swift 5 and Xcode 11, [Swift Package Manager](https://swift.org/package-manager/) supports the iOS, macOS, and tvOS build system. This support has also been greatly improved in Xcode 12 with the addition of non-source files, including asset catalogs, storyboards and nibs, core data models, and localization folders. It also supports [binary frameworks](https://pspdfkit.com/blog/2020/binary-frameworks-as-swift-packages/). It's clear that it's now viable for most iOS projects, and [many dependencies](https://getstream.io/blog/choose-ios-dependencies-wisely/) such as [Stream Chat](https://getstream.io/chat/) have implemented support for it.

![Image shows CocoaPods logo with an arrow pointing to a Swift Package Manager logo](https://i.imgur.com/KqSP9y3.png)

A quick [Twitter poll](https://twitter.com/cardosodev/status/1316016310044639248) showed that 46.5% of iOS developers still use CocoaPods as their primary dependency manager. Swift Package Manager follows just behind with 42.1%.

![Twitter poll shows 46.5% of CocoaPods usage, 42.1% of Swift Package Manager, and 11.4% of Carthage](https://i.imgur.com/qBrdtBD.jpg)

It's clear that SPM, with its recent improvements and deep integration with the official iOS toolchain, will soon take over the other options. In this article, I'll present a process that you can follow to migrate your projects to Swift Package Manager fully.

## Remove CocoaPods

To remove CocoaPods, you'll need the CocoaPods plugins `cocoapods-deintegrate` and `cocoapods-clean`. To install them, run `sudo gem install cocoapods-deintegrate cocoapods-clean`.

Before you remove CocoaPods, it's important to note each dependency in your project and their versions. In my case, I was only using [Stream Chat](https://getstream.io/chat/) in version 2.4.2.

{% gist https://gist.github.com/cardoso/09c3760434b673169746a81087b639a6 %}

Now, let's remove CocoaPods from your project. You should run the command `pod deintegrate` in the same folder the Podfile is in.

![Screen shows terminal with the pod deintegrate command executed and some lines of output](https://i.imgur.com/Hg04n1M.png)

That command removes the `Pods` folder and removes the settings CocoaPods inserted in your `.xcodeproj`.

Now, run `pod clean`. That command will remove some leftover files like `Podfile.lock` and the `.xcworkspace` originally generated by CocoaPods.

It's possible that your `.xcodeproj` still contains a reference to the `Pods` folder. You can remove it by right-clicking the folder and selecting 'delete'. It will be gone instantly.

![Screenshot shows Xcode with the Pods folder selected](https://i.imgur.com/11Ssc1c.png)

After you're done with these commands, you can put the last nail in CocoaPods's coffin with `rm Podfile`. Thank you, CocoaPods, you've been very useful. 😢

## Add Swift Package Manager

After you've mourned the loss of CocoaPods, let's replace it with SPM. Hopefully, you've taken notes of all the dependencies you had. 

Open your `.xcodeproj`, select the option "Add Package Dependency" in File > Swift Packages, and paste the URL of your dependency's git repository. For example: "https://github.com/getstream/stream-chat-swift".

![Screenshot shows Xcode with the Add Package Dependency dialog opened and Stream Chat iOS SDK GitHub URL in the input field](https://i.imgur.com/devTOtz.png)

After pressing next, Xcode will look for the repository and automatically select the latest version tagged. If this version is compatible with the one you were using, you can press next. Otherwise, type the version you were using. After that, Xcode will download the dependency.

![Screenshot shows an Xcode screen selecting a dependency version and an Xcode screen downloading that dependency](https://i.imgur.com/isVLxfL.png)

A repository may contain multiple targets. If that's the case, you should select only the ones you use.

![Screenshot shows an Xcode screen with dependency targets to be selected](https://i.imgur.com/ySfnql7.png)

After you press finish, it's done! Though, you must repeat this process for each dependency you had.

It's possible that a dependency doesn't provide a `Package.swift`. In that case, it can't be used with Swift Package Manager. However, you can clone the repository and add `Package.swift` yourself or request the maintainers to do so. For example, see the [commit adding SPM support to the Stream Chat iOS SDK](https://github.com/GetStream/stream-chat-swift/commit/e406e5c406a92af42af308ee828eb582bd15ec6d#diff-f913940c58e8744a2af1c68b909bb6383e49007e6c5a12fb03104a9006ae677e).

## Conclusion

I hope you were successful in transitioning your project to the future. It's only getting better from now on. If you need any help converting your project to Swift Package Manager, feel free to reach out to me on Twitter: [@cardosodev](https://twitter.com/cardosodev).