Doubts about running new syntax in an older version of Swift

I have an app that uses Swift 4.2. I am going to update the Swift Compiler Language to Swift 5. But I have some confusion after my test. I was able to run async/await code when using Xcode 15 with the version set to Swift 4.2, and it was okay. But async/await code was developed in Swift5.5. Why it is okay? Is it related to the Xocde Swift version? And if I use Swift Compiler version 4.2 to run async/await code,what problems might there be ?

Replies

That setting doesn’t control the Swift compiler version. You always get the Swift compiler that’s built in to Xcode [1].

Rather, it controls the Swift language version, that is, the version of the language that the compiler tries to accommodate. The language version matters in the rare cases where Swift changes behaviour in some incompatible way. The language version don’t limit what features you can use. So you’ll find that many Swift 5 features are available when the language version is set to Swift 4.2, as long as those features don’t cause source-level compatibility problems for existing Swift 4.2 source code.

I say “rare cases”, and that’s been true recently. However, the upcoming Swift 6 is going to involve a lot of changes, enforcing data race safety. Given that context, now is a good time to move forward to Swift 5. And, if you’re writing concurrent code, enable Strict Concurrency Checking.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Unless you install a custom toolchain.