Why this happens
Developers often see conflicting Swift versions because Apple separates the Swift compiler version from the Swift language version.
The compiler version is tied directly to the Xcode toolchain installed on your Mac. When you update Xcode, you receive a new compiler binary capable of parsing newer language features and optimizations.
However, each Xcode target specifies a language compatibility mode (SWIFT_VERSION). This build setting instructs the modern compiler to enforce legacy syntax and diagnostic rules so that older codebases compile without errors under a newer toolchain. Additionally, your command-line environment might point to a different Xcode installation than the one you have open on your desktop.
How to fix it
1. Check the target’s Swift Language Version in Xcode
To find the language version applied to your target’s source code during compilation:
- Open your project in Xcode.
- Select your project in the Project Navigator (left sidebar).
- Under Targets, click the target you want to inspect.
- Select the Build Settings tab.
- Ensure All and Combined (or Levels) are selected near the top.
- In the search field, type
Swift Language VersionorSWIFT_VERSION. - Locate the Swift Compiler – Language section. The value next to Swift Language Version displays the active compatibility mode (for example,
Swift 5orSwift 6).
If multiple targets exist in your project, check each target individually, as framework targets and app targets can use different language versions.
2. Check the command-line Swift compiler version
To see the version of the Swift binary currently executed by terminal tools and build scripts, run the following command in Terminal:
xcrun swift -version
The output displays the compiler release and build identifier:
Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx15.0
To ensure xcrun is resolving to the correct Xcode installation, verify the active developer path:
xcode-select -p
If the path points to /Library/Developer/CommandLineTools or a different Xcode version than intended, repoint it using:
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
You can also find the exact path to the swift binary being executed:
xcrun --find swift
3. Check the Swift version programmatically in code
You can conditionally check the compiler version at compile time using #if swift conditional compilation directives:
func printActiveSwiftVersion() {
#if swift(>=6.0)
print("Compiled with Swift 6.0 or newer")
#elseif swift(>=5.10)
print("Compiled with Swift 5.10")
#elseif swift(>=5.9)
print("Compiled with Swift 5.9")
#elseif swift(>=5.0)
print("Compiled with Swift 5.x")
#else
print("Compiled with an older Swift version")
#endif
}
Note that #if swift(>=...) checks the language compatibility version defined in your target settings, not the raw marketing version of the Xcode IDE.
How to prevent it
- Define
.swift-versionin your repository root if you use version managers likeswiftenvor custom CI/CD pipelines. - Set the
// swift-tools-version:header at the very top of yourPackage.swiftfile to lock Swift Package Manager dependencies to an explicit language level. - Configure
xcode-selectexplicitly in your automated CI build steps before invokingxcodebuildorswift test. - Review the Swift Language Version in Xcode build settings after upgrading major Xcode releases to decide when to migrate to new language modes.
FAQ
What is the difference between compiler version and language mode?
The compiler version is the executable binary shipped with Xcode that transforms source code into machine code. The language mode is a setting passed to that compiler (via the -swift-version flag) that controls whether newer language rules and strict concurrency checks are enforced.
Why does Terminal show a different Swift version than Xcode?
Terminal uses the developer directory set by xcode-select. If you have standalone Command Line Tools or multiple versions of Xcode (such as a release version and a Beta) installed, Terminal may resolve to a different toolchain until updated with sudo xcode-select -s.
Can I install and select custom Swift toolchains in Xcode?
Yes. You can download custom toolchains from swift.org and install them. In Xcode, navigate to Xcode > Toolchains in the menu bar to switch between the default Xcode toolchain and alternative installed toolchains.
Parts of this guide are adapted from content licensed under CC BY-SA 3.0; this article is shared under the same license.
