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

2

9

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)

Clausius answered 15/11, 2017 at 21:9 Comment(4)
Possible duplicate of Change Carthage Swift versionGirlhood
@DávidPásztor 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)Clausius
The same question was answered here Please, check it out.Extenuatory
@lib I don't have multiple version of XCode. I have XCode 9.1 which in theory should be able to compile Swift 3 and Swift 4. Question is how to tell Carthage to have XCode 9.1 use Swift 3.Clausius
M
7

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...
Moorman answered 21/11, 2017 at 7:30 Comment(1)
The swift compiler in Xcode 9 is compatible with both Swift 3 and Swift 4 in the same codebase. They are compiler-compatible. This rather seems a Carthage bug to me.Sprage
S
0

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

Scientist answered 24/11, 2017 at 0:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.