45

I have an existing project which uses Cocoapods, but I would like to switch to SPM; unfortunately I still have dependencies which aren't available in SPM.

Now I would like to move as many dependencies as possible over to SPM and keep the others in Cocoapods as long as necessary - is this possible? Having both, Cocoapods and SPM?

swalkner
  • 16,679
  • 31
  • 123
  • 210

4 Answers4

31

I just tried CocoaPods with SPM on my iOS project and it works fine.
I'm adding Firebase and other Google libs using CocoaPods and the rest using Swift Package Manager.

When adding SPM dependency, put checkmark on your project(s) and not on the Pods project.

Xcode 11.5,
CocoaPods 1.9.3.

Pavel Alexeev
  • 6,026
  • 4
  • 43
  • 51
  • 1
    is there a version you could upload somewhere public? Would be interested in how you did it... – swalkner Jun 26 '20 at 05:47
  • 2
    What if one of your private packages depends on a cocoapod library? do you have a way to link against that? – ShaLi Shaltiel Oct 19 '20 at 05:39
  • 4
    You should provide and answer and not just it's working... – Paul Nov 24 '20 at 03:03
  • 2
    @Paul, I added CocoaPods using `pod install` and then added SPM dependencies using File → Swift Packages → Add Package Dependency and ticking my project (and not Pods project) – Pavel Alexeev Nov 26 '20 at 08:54
  • 1
    @PavelAlexeev Thanks did it already though. Thanks for the response really appreciate. I just simply added a Package using SPM within the same project where I had used CocoaPods/other packages and it worked no issues. – Paul Nov 27 '20 at 23:53
1

After trying it out I found you can actually have a SPM + Cocoapods to play nice. You install your SPM library on the .xcodeproj while you develop on the .xcworkspace. It all works (at least so far for me lol).

If you are using CI, or you launch manually from xcodebuild command some tweaks with the -clonedSourcePackagesDirPath flag

wolffan
  • 1,084
  • 10
  • 15
0

I have had used swift package manager at the beginning and added 4 packages in my project. When I had to integrate admob sdk. I added cocoapod to my project. but after open the .xcworkspace file. the packages status are display as Missing. I have to add them from SPM one by one. after all 4 packages were added again. the project can be built and executed again.

dqshll
  • 121
  • 1
  • 5
-8

Considering all the pros and cons, I found it suitable to use CocoaPods as SPM is still at a very nascent stage and not all libraries support it. Please go through the blog written by Darshan Patel by https://blog.kiprosh.com/preferable-dependency-manager-swift-package-manager-spm-or-cocoapods/ for more details.

Saloni
  • 1
  • 1