Tell Carthage to build dependency using Swift 3.2.2 (NOT Swift 4.0)

Viewed 3366

I have a project written in Swift 3.2.2 and compiled using XCode 9.1

I have a dependency which is built using Carthage using this command:

carthage update --platform iOS

The issue is that Carthage builds the dependency using Swift 4.0 (instead of Swift 3.2.2)

Module compiled with Swift 4.0 cannot be imported in Swift 3.2.2

How do I tell Carthage to build my dependency using Swift 3.2.2 so that it can be used in my project?

I don't want to upgrade my project to Swift 4.0 quite yet.

Xcode 9.1 has support for both Swift 3 and Swift 4. So how do I tell Carthage to use Swift 3 when compiling the dependency? I don't want to tell it to use an earlier version of XCode (which I don't have anymore)

2 Answers

You say:

  1. your project is compiling in Swift 3.2.2
  2. your dependency, once resolved and downloaded with Carthage, will be compiling in Swift 4 (since its Build Setting was configured in that way)

with those conditions will be impossible for you resolving the issue: you can't mix Swift 3 and 4 due to this: https://github.com/Carthage/Carthage/issues/1978

The only thing you can do, for (eventually) fixing the situation is:


Scenario 1

  1. you should find a previous version of the library which is building in Swift 3.2~, if exists
  2. on your Cartfile you specify that specific version, eg:

    github "yourDependency" == x.y.z


Scenario 2

  1. launch carthage update --platform iOS
  2. enter inside your dependency folder (Carthage/Checkouts/yourDependency) and open the .xcodeproj in order to modify manually this option:

enter image description here

  1. then you might have tons of building problems due to the fact that you are producing a language regression, you can try to fix them (depending by the library if is small or not, it could be possible).
  2. if you have solved the dependencies, then launch:

    carthage build --platform iOS

  3. try to compile your project...

The only workaround for now is to switch to new build system in Xcode. In workspace settings. Or downgrade library version which supports swift 3

Related