Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Swift 3 in Xcode 10.2 - Command /Library/Developer/Toolchains/swift-3.0-RELEASE.xctoolchain/usr/bin/swiftc failed with exit code 1

Tags:

xcode

ios

swift

My goal is to get the new Xcode 10.2 compile and run our projects that are build using Swift 3 and 4.2 (some cocoapods too) and since Xcode 10.2 comes with Swift 5, an unsupported swift error came up when trying to run the projects out of the box (this is expected):

enter image description here

The solution here is to use an older toolchain as stated on blogs like this, which i did.

enter image description here

All good so far. However, after installing the Swift 3 toolchain from Swift.org, compiling the project will bring the following error:

Command /Library/Developer/Toolchains/swift-3.0-RELEASE.xctoolchain/usr/bin/swiftc failed with exit code 1

enter image description here

I already deleted Derived Data folder, cleanup pods (my podfile) and reinstalled them, restarted Xcode and Mac multiple times.

Running xcrun -f swift and swift --version will indeed print the correct swift 3.0 toolchain

enter image description here

Yes, I know I could just stay with Xcode 10.1 and don't have these issues. Code migration to Swift 4 is also an option but we don't have the time at hand for now so I'm trying to workout this walkaround.

Please help me to resolve this issue, I'm completely stuck. Thanks in advance.

like image 976
Radu Ursache Avatar asked Mar 26 '19 07:03

Radu Ursache


People also ask

How to install alternative toolchain for Swift in Xcode?

Xcode comes by default with the latest stable toolchain release of the Swift, thankfully it supports using alternative toolchains instead of default one out of the box. All we have to do is install the alternative toolchain that is available to download from swift.org website.

How do I run xcrun and xcodebuild in a different toolchain?

To use the alternative toolchain you can run xcrun and xcodebuild with a -toolchain flag like this: where NAME is either an identifier or name of the toolchain, ie. xcodebuild --toolchain swift. You could also export it to your current terminal session with a command:

How to integrate swiftlint with Xcode?

Integrate SwiftLint with Xcode In order to integrate SwiftLint with Xcode project target to get warnings and errors displayed in the Xcode IDE, you just need to add a new "Run Script Phase" with following script - If you don't know how to add a "Run Script Phase" in your project target, here an image for your reference -

What version of Swift is running on x86_64-apple-darwin19?

Apple Swift version 5.1.3 (swiftlang- 1100.0.282.1 clang- 1100.0.33.15 ) Target: x86_64-apple-darwin19. 3.0 To use the alternative toolchain you can run xcrun and xcodebuild with a -toolchain flag like this:


2 Answers

Xcode10.2 Release Notes

Swift 5 no longer supports the Swift 3 Package.swift tools-version. Packages still on the Swift 3 Package.swift tools-version should update to a newer tools-version. (41974124)

Swift 5.0

Source Compatibility As with Swift 4.2, the vast majority of sources that built with the Swift 4.2 compiler should compile with the Swift 5.0 compiler.

However, the Swift 3 compatibility mode will not be supported in the Swift 5 compiler. Swift 4.2 is the last release of Swift to support Swift 3 mode. There are important changes to both the surface of the language and the interior of its implementation in the releases following Swift 3 that will be the basis of future (and lasting) source and binary stability.

like image 82
Vinay Kiran Avatar answered Oct 20 '22 01:10

Vinay Kiran


Using Swift 4.2.1 toolchain work for me.

But https://swift.org/download/#using-downloads tips:

To submit to the App Store you must build your app using the version of Swift that comes included within Xcode.

Upload to apple connect probably reject by apple.

like image 28
Eric Avatar answered Oct 19 '22 23:10

Eric