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

*爱你&永不变心* 提交于 2020-02-19 12:34:08

问题


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.

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?


回答1:


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.



来源:https://stackoverflow.com/questions/57914703/swift-build-settings-in-xcode-to-use-lower-4-0-3-version-instead-of-5-0-1-are-no

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!