Use Xcode project and Package.swift together?

Hey! I just wrote this StackOverflow question but figured it might be a good thing to ask for help on Swift Forums.

Specifically, I wonder if anyone of you knows if it is somehow possible to use an Xcode Project file together with declaring (creating) a Swift Package, and use all the dependencies resolved through swift package update in the Xcode project file? (Or if you have any other idea solving my issue, that is, of course, most welcome as well...)

1 Like

First, to your overall situation:

As long as BitcoinKit’s own package support is broken, there is no means of using it from SwiftPM.

The feature you would need to work around it as a client is support for binary dependencies. The most up‐to date thread on the subject seems to be this one:

The other thread you already linked from StackOverflow is older, but also still relevant.

I don’t know how broken it is, but you may also be able to fix BitcoinKit’s package support for them, or at the very least fork it and get enough of it working so you can depend on your fork instead.


I'm developing a Swift library/SDK, and up until now, I've been using Carthage for dependencies. But since SPM finally works with iOS, I feel it would be great for people who want to use this library to be able to include it via SPM.

I understand that to mean that you still want clients to be able to continue depending on your library with Carthage according to their preference. In that case, you likely need to manage the two side‐by‐side and independent of one another. (If you wrangle one of your dependencies out of one package manager and embed it into your package for use with the other, you run the risk of a client attempting to use both your package and the same dependency in their dependency graph, in which case they would end up with duplicate modules.)

However, if your package does not need to worry about any clients of its own, then it doesn’t matter.


Second, to your specific question:

There are two methods.

  1. Use Xcode 11’s new package support. The clearest instructions seem to be in this thread:
  1. Use swift package generate-xcodeproj. Then include that project in an Xcode workspace alongside another Xcode project that contains the Xcode‐only stuff.

At the moment there are corner cases with discrepancies between how the two strategies behave. It is possible (though unlikely) that only one or the other of the two methods will work for your specific package (until the related bugs are fixed).

Carthage may have (or be working on) its own solution for integrating SwiftPM packages. It might be worth asking in that community too.

A similar question was recently asked here:

The poster of that topic was trying to assemble a public template for Swift projects. The result is rather opinionated (for example, you could easily licence your project without realizing it). But I do remember both Carthage and SwiftPM coming up in the discussion, so it might be worth taking a look to see at least one way of vending a single project for use with either tool.

Thanks for the ping. I have researched the topic very much and have worked on a similar project setting the default template for CocoaPods (the pod-template project).

For advanced users, I recommend starting with GitHub - fulldecent/swift5-module-template: An opinionated starting point for awesome, reusable Swift 5 modules and going straight to the RECIPE.md. This shows you click-by-click starting with "open Xcode, version 11.1" and going through every click and word you type in to get to the desired result, which is a Swift module and example app. By following the RECIPE line-by-line you will avoid adopting any opinionated things (such as the default license) which you don't want.

1 Like