Xcode 9 Swift Language Version (SWIFT_VERSION)
Answer to your question:
You can download Xcode 8.x from Apple Download Portal or Download Xcode 8.3.3 (or see: Where to download older version of Xcode), if you've premium developer account (apple id). You can install & work with both Xcode 9 and Xcode 8.x in single (mac) system. (Make sure you've Command Line Tools
supporting both version of Xcode, to work with terminal (see: How to install 'Command Line Tool'))
Hint: How to migrate your code Xcode 9 compatible Swift versions (Swift 3.2 or 4)
Xcode 9 allows conversion/migration from Swift 3.0
to Swift 3.2/4.0
only. So if current version of Swift language of your project is below 3.0 then you must migrate your code in Swift 3 compatible version Using Xcode 8.x.
This is common error message that Xcode 9 shows if it identifies Swift language below 3.0, during migration.
Swift 3.2 is supported by Xcode 9 & Xcode 8 both.
Project ► (Select Your Project Target) ► Build Settings ► (Type 'swift' in Searchbar) Swift Compiler Language ► Swift Language Version ► Click on Language list to open it.
Convert your source code from Swift 2.0 to 3.2 using Xcode 8 and then continue with Xcode 9 (Swift 3.2 or 4).
For easier migration of your code, follow these steps: (it will help you to convert into latest version of swift supported by your Xcode Tool)
Xcode: Menus: Edit ▶ Covert ▶ To Current Swift Syntax
What is the Swift Language Version Xcode setting for? Because it still builds newer Swift code with an older version set
Prior to Swift 4, the version of the compiler and the language were one and the same. But since Swift 4, the compiler can run in a compatibility mode for previous Swift versions. check more info on compatibility modes in the Swift 4.0 release notes
The Xcode build setting SWIFT_VERSION
set's the compiler flag -swift-version
which is the language mode. From the swift compiler print out below this parameter only changes how the input is interpreted.
swiftc -h|grep 'Swift language version number'
-swift-version Interpret input according to a specific Swift language version number
Thus When you select Swift Language Version to 4.2, this does not mean use Swift 4.2 compiler. The compiler version will still be 5.1.3, the Swift Language Version setting instructs the compiler to run in Swift 4.2 compatibility mode. The compatibility mode means you may not need to modify your swift 4.2 code to use the new version of the compiler. Because the compiler running in compatibility mode allows Swift version 4.2 code to compile and run alongside code from version 5 and later.
The Swift 5 compiler with compatibility mode can compile code written with either Swift 4 syntax, Swift 4.2 syntax, or Swift 5 syntax.
Here is a code example, create a file test.swift with code below:
//code written before siwft 5
let firstName = "michael jackson"
let offset = firstName.endIndex.encodedOffset
// Check swift version being used.
#if swift(>=5.2)
print("Hello, Swift 5.2")
#elseif swift(>=5.1)
print("Hello, Swift 5.1")
#elseif swift(>=5.0)
print("Hello, Swift 5.0")
#elseif swift(>=4.2)
print("Hello, Swift 4.2")
#elseif swift(>=4.1)
print("Hello, Swift 4.1")
#elseif swift(>=4.0)
print("Hello, Swift 4.0")
#endif
suppose the above code was written before swift 5 using the swift 4 compiler
this code will compile with no error's as shown below.
After swift 5 is released if you try to compile this code with Swift 5 compiler as shown below.
You will get the warning shown above since encodedOffset
is deprecated in swift 5.
You could downgrade and use the swift 4 compiler or you can use the Swift 5 compiler in compatibility mode with the compiler flag -swift-version as shown below.
It's important to note that Swift 4 compiler, and the Swift 5 compiler in Swift-4 compatibility mode are not the same thing. New swift 5 language features are normally available to the swift 5 compiler running compatibility mode. This allows developers to use the new features even when they can't upgrade to swift 5. The new Swift 5 features will not be available to the Swift 4 compiler.
“Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift
In the navigator selection bar, click the magnifying glass, then search for "SWIFT_VERSION
" You will find the places in the project where you can adjust the swift version accordingly.
The “Swift Language Version” (SWIFT_VERSION) build setting error with project in Objective C
For Objective C Projects created using Xcode 8 and now opening in Xcode 9, it is showing the same error as mentioned in the question.
To fix that, Press the + button in Build Settings and select Add User-Defined Setting.
Then in the new row created add SWIFT_VERSION as key and 3.2 as value like below.
It will fix the error for objective c projects.
The “Swift Language Version” (SWIFT_VERSION) build setting must be set to a supported value for targets which use Swift
The error is pretty clear.
- In the project navigator select the (blue) project
- Select the target which uses Swift
- Click on
Build Settings
- Scroll down to
Swift Language Version
or in the search field typeSwift L
- In the popup of the setting select the language version
Swift Language Version' option is missing in Xcode 9.1 Build Setting
You appear to have an Objective-C project rather than a Swift project. Objective-C projects do not have a Swift Language Version setting as a default.
You can add Swift Language Version as a User-Defined Setting, as described here.
How to fix SWIFT_VERSION error on PhoneGap Build
I use Cordova in my Ionic project and set the swift version in the following way. I hope this helps you as well.
By default, the Swift 4 support is added but the legacy version (2.3) can still be configured as a preference, inside the project's config.xml
, within the
section:
Or it is possible to specify the version as following, inside the project's config.xml
, within the
section:
Your plugin is using this swift dependency, you can check this link for more info: https://www.npmjs.com/package/cordova-plugin-add-swift-support
“Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift.
Xcode 8 seems to be wrongfully displaying a nonexistent ("phantom", if you will) No
. There's a trivial fix for this:
- Click the tiny arrow next to
SWIFT_VERSION
to toggle the drop-down list. - Set the values for
Debug
andRelease
toYes
. - Set the values for
Debug
andRelease
back toNo
.
The image below was taken just after setting Debug
to No
. Xcode shows that both Debug
and Release
are set to No
, however SWIFT_VERSION
reads
:
From this, I can only conclude that it is a bug; and that some value (or more probably a null value) is being misrepresented as No
.
Related Topics
Dyld'_Abort_With_Payload: Without an Error Message
Connect Objective-C Framework to Swift iOS 8 App (Parse Framework)
Check If Property Is Set in Core Data
Setting Direction for Uiswipegesturerecognizer
Avfoundation, How to Turn Off the Shutter Sound When Capturestillimageasynchronouslyfromconnection
Invalid Swift Support - Files Don't Match
How to Implement a Pop-Up Dialog Box in iOS
Present Modal View Controller in Half Size Parent Controller
Are Nslayoutconstraints Animatable
Debugging App When Launched by Push Notification
Wrong Color in Interface Builder
Load View from an External Xib File in Storyboard
How to Rotate Text for Uibutton and Uilabel in Objective-C
How to Correctly Handle Weak Self in Swift Blocks with Arguments
Expandable Tableview in Iphone