Skip to content

Instantly share code, notes, and snippets.

@ngtrphuong
Forked from thesailordev/Carthage2Cocoapods.md
Created September 10, 2021 03:08
Show Gist options
  • Save ngtrphuong/b9f136049272758b10fd62fcee0ed1e2 to your computer and use it in GitHub Desktop.
Save ngtrphuong/b9f136049272758b10fd62fcee0ed1e2 to your computer and use it in GitHub Desktop.
Convert a Carthage Dependency-Managed Project to Cocoapods

Carthage to Cocoapods

We recently had the need to align our frameworks to one dependency management system. Previously we were using Carthage and Cocoapods (or both) amongst different frameworks. The burden of supporting both platforms coupled with long build times on our CI/CD drew us away from Carthage. During this conversion I encountered several "gotcha" moments in our Xcode projects that I want to share with others who might be doing the same thing to get you to a clean Cocoapod based build.

Assumptions

  • You have a working knowledge of Carthage and Cocoapods
  • You have a working knowledge of Xcode project settings
  • If you use bundler you will need to add that to the commands listed

Steps

  1. To start with, you will want to create a Podfile and/or Podspec file that matches the dependencies defined in your Cartfile and Cartfile.private files.
  2. Delete the Carthage directory
  3. Delete the Cartfile and Cartfile.resolved files (but save the libraries you want to use somewhere safe)
  4. Ensure you do the following steps for all your Xcode targets (build, tests, UI tests, etc)
  5. In Xcode, highlight your project in the Navigator view, select Build Settings -> Framework Search Paths, delete what is there, and add this string “$(inherited)”
  6. Select Build Settings -> Header Search Paths and delete the entries
  7. Select Build Settings -> Other C Flags, delete what is there, and add this string $(inherited)
  8. Select Build Settings -> Always Embed Swift Standard Libraries and delete what is there
  9. Select Build Phases and delete Copy Frameworks
  10. In Terminal cd to the parent directory of your project and run pod init to initialize Cocoapods in the project
  11. Run pod install
  12. Ensure your Podfile.lock references all the libraries as your old Cartfile.resolved
  13. Open your new *.xcworkspace file and ensure that your project builds

You should now have a working Cocoapods project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment