How to check current swift version that you are using

In this tutorial, we will show you how easily we can check the current swift version that we are using right now.

There might be solutions based on how you have installed swift on your machine.

At first, I will show you the easiest way to find your swift version.

Check swift version if you have installed XCode

If you have installed Xcode on your machine then open the terminal and simply write the below command.

swift --version

For my PC I have got this output.

codespeedy@Saruques-MacBook-Air ~ % swift --version
swift-driver version: 1.26.9 Apple Swift version 5.5.1 (swiftlang-1300.0.31.4 clang-1300.0.29.6)
Target: x86_64-apple-macosx12.0

How to check current swift version that you are usingTip:

This is not necessary that the same version will take action in Xcode as well. As you can install swift outside without Xcode.

So the best option to see which version you are using in XCode is below provided.

Find swift version – using swift programming

#if swift(>=5.2)
print("You are using, Swift 5.2")
#else
print("Earlier than 5.2")
#endif

Run this code online

It will give you the output based on your if-else condition.

For me I get this output:

You are using, Swift 5.2

Actually, #if swift – is a build configuration option that lets us run certain parts of the code if only a specific swift version is detected.

Some information to know the swift version based on Xcode version

Xcode 13 — Swift version 5.5

Xcode 12— Swift version 5.3

Xcode 11—  Swift version 5.2

Also read: Create a playground in Xcode 13 and newer versions

Leave a Reply

Your email address will not be published.