Swift build settings in Xcode to use lower 4.0.3 version instead of 5.0.1 are not enforced
Asked Answered
C

1

7

I'm creating a simple Swift framework in Xcode 10.3 and trying to use a lower Swift 4.0.3 version. I went to the Xcode build settings and switch from 5.0.1 to 4.0.3 and then build the project.

enter image description here

I ran otool against resulted framework to make sure it's built using correct Swift version but the libraries included are still from Swift 5.0.1 (corresponds to 1001.0.82 from the output below):

otool -l SwiftyHello.framework/SwiftyHello

cmd LC_LOAD_DYLIB
cmdsize 56
name @rpath/libswiftCore.dylib (offset 24)
time stamp 2 Wed Dec 31 16:00:02 1969
current version **1001.0.82**
compatibility version 1.0.0

My toolchain is running Swift 5.0.1:

swift -version

Apple Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.5)
Target: x86_64-apple-darwin18.7.0

How can I make sure that the Swift framework is built using Swift 4.0.3?

Christabella answered 12/9, 2019 at 21:24 Comment(4)
Did you find solution for this issue?Hoopla
Unfortunately, noChristabella
Did you try changing your tool chain as well using Preferences=> Toolchains and set it to what version you need?Overlive
@Overlive tried that also, But sadly didn't work.Hoopla
P
6

SWIFT_VERSION (Swift Language Version) key does nothing with an actual Swift version of the resulting binary. From $ swift --help:

-swift-version Interpret input according to a specific Swift language version number

So, basically, Xcode executes Swift compiler with -swift-version 4 argument. It changes how Swift compiler parses the source files, but do not affect the binary in any way.

To build the actual Swift 4 binary, you have to install the Swift 4 toolchain. Then you would be able to pick the correct toolchain from the menu Xcode -> Toolchains. But, honestly, I wouldn't recommend doing this way, because Apple does not care about older versions of toolchains, and Xcode usually behaves unstable with them.

Instead, I'd recommend you install older Xcode (in your case 9.3) from the Apple Downloads website and build the project from there.

Alternatively, you can set up relatively simple CI/CD inside Github Actions, CircleCI or TravisCI and build in multiple Xcode versions at the same time there. And use the latest Xcode locally. Because they these CIs provide you multiple virtual environments with different Xcode and macOS versions.

Pleuro answered 15/11, 2019 at 0:55 Comment(3)
@Albi, I'd say the best way is to install an older version of Xcode.Pleuro
It won't help ppl who are using new versionHoopla
is there any solution?Hoopla

© 2022 - 2024 — McMap. All rights reserved.