Moving From Cocoapods to Swift Package Manager |

This is a companion discussion topic for the original entry at
1 Like

Is there a simple manner to tell if a CocoaPod is converted to work with SPM?

If the repo has a Package.swift manifest file then it should be good to go (assuming they check it actually works etc)

Great screencast. Clear and concise. I was just starting to creating private Cocoapods for projects yesterday. Then I saw this show up. Now going to explore SMP.

I’m glad you enjoyed it! Check out @joannis’ SPM tutorial

And the next screencast will be about creating a package in Xcode!

1 Like

Perfect! I will check it out and eager for how to create my own in Xcode. Thanks again.

great but there is one thing I don’t understand, if you are the one hosting the dependancy on GitHub, usually you have your Cartfile and Pod files at the root level of your projects.

For SPM consumption, I know you need to have a Package.swift manifest file, but If I try to add it manually in my dynamic library it says No such module ‘PackageDescription’


@giguerea so creating libraries that work across SPM, Cocoapods and Carthage is a little more complicated. I’ve got an example of it here. Also take a look at the SPM post by @joannis here.

If you have any questions though feel free to ask! Where were you getting the error? Was it at build time?

There’s a problem I haven’t solved about SwiftPM.

If there is a package be hosted on github, then I would mirror this repo into my private git service in case sometime the github repo be removed. So, when I mirrored this package repo and all its dependicies to my own git service, the Package.swift manifest file record it’s depenticies all from github repo. Is there any solution can’t solve this problem. For Cocoapods, this can be solved by building private pod specs repo from those mirrored repos without modified their content, but for SwiftPM, maybe I should modify all Package.swift manifest files of Mirrored repos URL to adjust my own git service. If the domain of my own git services change. the process should be executed again. That’s inconvenient. Have you any solution to solve these problem?

Unfortunately that’s one of the issues that the community are currently trying to solve at the moment, but since SPM is completely decentralised the only way to solve it is fork the repo and point to the new URL. And if any of those packages have dependencies then yes you need to change all those URLs as well.

The benefits of this are of course you aren’t relying on a single directory that becomes a single point of failure or takes ages to update. For most people just sticking with the defaults will be fine. If you have a slightly different risk profile (something like a bank or using mission critical software) then you may want to mirror everything but that’s overkill for 99.99% of developers since GH is big enough for everyone. If GH were to disappear then the community could just push their packages to another provider and everyone would have to update their URLs, which would be painful but not world-ending, which is probably a good enough compromise

Is the new SPM part of Xcode 11 compatible with Vapor projects? Currently, we use the Vapor Toolbox from the command line to recreate Xcode projects using details from Package.swift. I just have not had time yet to try that part of Xcode 11 beta.

I finally find a way to make it works, not sure it’s the best way or the official way to do it

let say you already have your iOS project on GitHub (in my case it’s a dynamic framework)

  1. You create your package swift file manifest (Package.swift)
  2. I added it at the root level of my project where my xcodeproj file is
  3. At this point if you try to build in Xcode you will get an error saying No such module ‘PackageDescription’
  4. Close Xcode, double click your Package.swift file from finder, that will open Xcode and you will now be able to build your project without error, also it will change your project icon for a package icon
  5. I can see under git it created a hidden folder called .swiftpm


1 Like

@giguerea Thank you for sharing your solution - much appreciated! :]