How to add Carthage support in existing CocoaPod project
I’ve finally found some free time to review the contributions on AHDownloadButton repo and prepare a new release. Before releasing a new version I wanted to add support for Carthage, because the project is currently only supporting CocoaPods. Carthage is a great lightweight dependency manager and if you haven’t used it yet, I suggest you read up on it on.
Even though I’ve used Carthage as a dependency manager in one of my project, I’ve never had to add support for it in my personal libraries. In this short blog post, I’ll describe how you can add Carthage support for a library that already supports CocoaPods.
Sharing the Xcode schemes
Adding support for Carthage is quite easy, compared to CocoaPods, as there are no additional files required (like the
.podspec file). The only thing you need to do is to share the Xcode scheme that you want to build. To do that you have to:
Open the workspace/project that contains your pod.
Select the Shared checkbox for your pod scheme.
To test if the scheme builds successfully you can run
carthage build --no-skip-current.
If you created your pod using
pod lib create you might see that all schemes are already shared. That is what confused me the first time, since my library had all the schemes marked as shared but failed
carthage build with error message:
*** Skipped building AHDownloadButton due to the error:
Dependency "AHDownloadButton" has no shared framework schemes
After further investigation I noticed that the
.xcodeproj/xcshareddata/xcschemes/AHDownloadButton.xcscheme file was missing. This file is created when the scheme is shared but Xcode didn’t create it. A simple fix is to just uncheck and check the shared checkbox and the file should be created. After that, you just have to commit the file and push the changes to your repository.
Prebuilding and archiving the framework
Instead of building your library from scratch, Carthage can use the prebuilt framework if it is attached to the release of the library on GitHub. To archive the library simply run:
carthage build --no-skip-current
carthage archive YourFrameworkName
This will create a zip archive of your framework that you can upload on GitHub when you release a new version of your library.
This step is not mandatory but is good for the users of your library to be able to download the framework directly from the release.