How to migrate your swift project from CocoaPods to SwiftPM

Milan Panchal
4 min readNov 25, 2020

--

Migrate your Swift project from CocoaPods to SPM
  • We’re using Cocoapods for several years, but Swift Package Manager (SPM) is new standard dependency manager which included in Swift 3.0 and above. If you are the one who wants to adopt SwiftPM in your swift project, this is how to do it right.
  • Before removing CocoaPods from your project, make sure all your dependencies are compatible with SwiftPM.
  • I’ve found one small tool spmready by Humi to check If all your dependencies are ready to migrate to SwiftPM or not.
  • If all your libraries are not compatible with SPM , then either you go ahead with CocoaPods + SPM together or just leave as it is.
  • If you are still want to integrate SPM for all compatible dependencies along with CocoaPods then skip the removal process of CocoaPods.

Steps to Remove CocoaPods from your Project:

To remove CocoaPods from your project, you need to install cocoapods-deintegrate and cocoapods-clean gems.

Open your terminal application (ApplicationUtilitiesTerminal.app) and run the following commands:

$ sudo gem install cocoapods-deintegrate
$ sudo gem install cocoapods-clean

or you can combine both the commands as follow:

$ sudo gem install cocoapods-deintegrate cocoapods-clean

NOTE: Before removing CocoaPods from your project, its advisable to take backup of your project and most importantly, version of the each library you are currently using. You can find all the libraries and their version in the Podfile.lock file of your project’s root directory.

After successfully installing the gem, navigate to your project’s root directory in terminal and run following commands:

$ pod deintegrate  // 1
$ pod clean // 2
$ rm Podfile // 3
  1. First command will remove the Pods folder from your project and all the CocoaPods linking from .xcodeproj file added during CocoaPods integration.
  2. Second command will remove the Podfile.lock and the .xcworkspace file, which was created during CocoaPods integration.
  3. Final command will remove the Podfile from your project.

Now, open your project in Xcode using .xcodeproj file and remove Pods folder if it contains any reference.

That’s it. You have successfully deintegrated CocoaPods from your Project.

Deintegrate CocoaPods from your iOS Project

Integrate libraries using SwiftPM in your Project:

We have successfully removed CocoaPods from our project. Now, It’s time to install all our dependencies/libraries using Swift Package Manager.

As earlier said, before deintegrating CocoaPods from your Project make sure all the libraries that you are using is your project is available using with SwiftPM.

  • Open your project in Xcode using .xcodeproj file.
  • Navigate to FileSwift PackagesAdd Package Dependency…
Add Project Dependency
Choose Package Repository
  • Now, Xcode will start looking for your repository and automatically select the latest version tagged. You can also choose the different version, branch or specific commit.
  • Now click on the Next button and Xcode will download the selected dependency package.
Choose Package Version, Branch or Commit
  • The repository may contain multiple package products. If that’s the case, you should select the ones you need and click on Finish button.
  • That’s it. You have successfully integrated your dependency/library via SPM
  • Now, repeat this process for each and every dependency that you have.

Conclusion

  • Swift Package Manager will soon replace CocoaPods for integrating third-party libraries into your project.
  • Checkout WWDC19 session 408 — Adopting Swift Packages in Xcode, to learn more about Swift Package Manager.

I have created Poll on Twitter to see which dependency manager iOS developers are using now a days. Please select the appropriate option.

Questions?

Please feel free to comment below, if you have any questions.

If you like this article, feel free to share it with your friends and leave me a comment. Also, click on the 👏 clap button below to show how much you like the article.

Thanks for reading! 👨🏼‍💻

You can find me on:

Twitter | LinkedIn | GitHub | Medium | HackerRank | LeetCode | Stack Overflow

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

iOS Team Lead ǁ Swift ǁ Objective-C ǁ Lifelong Learner ǁ Blogger — Join Medium from the following link: https://medium.com/@milanpanchal24/membership