What Versions of Swift Are Supported by What Versions of Xcode

What versions of Swift are supported by what versions of Xcode?

Since I've been gathering data and doing tests, I'll post my results as an updated chart in this answer:

A chart depicting the different versions of Swift as compared to their respective versions of Xcode. Last updated 2020-02-25

Awhile ago, I found out that newer versions of Xcode do not, in fact, support migrating from all older versions of Swift. I did explicitly test that Xcodes 10.2 through 11 don't support Swift 3.x and earlier, so I colored those white. I've not yet had time to test Xcode 8.3 through 10.1, but I suspect they will migrate 3.x but not 2.x or earlier; that's why there's a big "Unknown" block at the top.



Sources

  • Manual testing with this test code: https://github.com/BenLeggiero/Swift-Version-Checker
  • Xcode Release Notes
  • Swift Release Notes

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 <vers> 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.

compiler options

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.

Sample Image

After swift 5 is released if you try to compile this code with Swift 5 compiler as shown below.

Swift 5 compiler

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.

Swift 5 compiler with compatibility mode

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.

will older versions of swift work with newer iOS versions?

Swift versions are irrelevant to what iOS version you are developing for. However, Xcode version does matter, since the newest iOS runtimes are only available in the newest Xcode versions.

This doesn't necessarily mean that if you use an older Xcode version, your app wouldn't run on newer version, but you couldn't test your app on newer versions directly from Xcode. Moreover, Apple doesn't allow uploads to the AppStore using old Xcode versions.

From March 2019, only apps built with Xcode 10 are accepted, while from April 2020, only apps built with Xcode 11 will be accepted to the AppStore, as described in the AppStore Submissions page.

So if you want to be able to release your app, you'll need to upgrade your Xcode (and hence your laptop as well).

Which version of xcode supports Swift programming language ?

Swift programming language was introduced in Xcode 6 beta version.

Xcode 6 has deep support for Swift throughout. It’s easy to create a brand new app using 100% Swift code, add new Swift code or frameworks to existing apps, and view documentation in either Swift, Objective-C, or both. All the popular affordances such as “Jump to Definition” or “Open Quickly” work equally well with Swift, and even Objective-C header definitions can be shown in Swift syntax.

Please refer the following links for more detail:

  • https://itunes.apple.com/us/book/swift-programming-language/id881256329?mt=11
  • https://developer.apple.com/xcode/

Change Swift Version Project is Built With

I think what you mean is the version of swift-tools that gets invoked rather than swift. Change the first line of Package.swift in your project's folder to use the current version needed by the latest vapor version 4:

// swift-tools-version:5.5

Then use Xcode to try to build. If this doesn't work, try Using the Clean Build Folder menu option off the Product menu and try again.

Failing this, use terminal to remove the .build folder in your project's folder and do a swift package update followed by a swift build. I know of at least one swift compiler bug that means a compile that fails with swift build will succeed with swift build -c release so it could be worth trying both.

If all this fails, include more detail in your question to show the exact cause of 'will no longer build'.

What's the acceptable swift version for app submission?

Here is an excerpt from Apple:

Starting March 27, 2019, all iOS apps submitted to the App Store will
need to be built with the iOS 12.1 SDK or later, and support the
all-screen design of iPhone XS Max or the 12.9-inch iPad Pro (3rd
Generation). All watchOS apps will need to support watchOS 5 and Apple
Watch Series 4

This means that any submissions to App Store after March 27, 2019 requires iOS 12.1 SDK or later which I believe is available in XCode 10.2 onwards. XCode 10.2 doesn't have support for Swift 3. In essence, Apple stopped accepting applications written in Swift 3 after March 27, 2019.

The same principle would apply to Swift 4. Whenever they decide to up the minimum SDK requirement, it would force a minimum XCode version which, in turn, would force minimum Swift version

How to build for newer iOS versions with outdated Xcode?

Yes. You can use iOS 14.7 on Xcode 12.4. You only need to add device support file in Xcode for iOS 14.7.

You need to add device support file from this link



Related Topics



Leave a reply



Submit