How to Check & Change Swift Version in Xcode

In our existing older projects sometimes we face errors because of the older or newer used Swift Version. Following is the simplest way to check and change the Swift version in Xcode.

Check Project Swift Version

We can check currently used Swift version in our IOS project by navigating to

App -> YOUR_TARGET -> Build Settings -> Swift Compiler Language

In Build Settings you can search with “swift” string. Please see the following screenshot.

Check Swift Version Programmatically

We can also check the current Swift version programmatically by writing the following Swift code.

func printCurrentSwiftVersion() {
#if swift(>=5.2)
print("Current Swift Version: Swift 5.2")

#elseif swift(>=5.1)
print("Current Swift Version: Swift 5.1")

#elseif swift(>=5.0)
print("Current Swift Version: Swift 5.0")

#elseif swift(>=4.2)
print("Current Swift Version: Swift 4.2")

#elseif swift(>=4.1)
print("Current Swift Version: Swift 4.1")

#elseif swift(>=4.0)
print("Current Swift Version: Swift 4.0")

#elseif swift(>=3.2)
print("Current Swift Version: Swift 3.2")

#elseif swift(>=3.0)
print("Current Swift Version: Swift 3.0")

#elseif swift(>=2.2)
print("Current Swift Version: Swift 2.2")

#elseif swift(>=2.1)
print("Current Swift Version: Swift 2.1")

#elseif swift(>=2.0)
print("Current Swift Version: Swift 2.0")

#elseif swift(>=1.2)
print("Current Swift Version: Swift 1.2")

#elseif swift(>=1.1)
print("Current Swift Version: Swift 1.1")

#elseif swift(>=1.0)
print("Current Swift Version: Swift 1.0")

#endif
}

Change Project Swift Version

As you can see in the above screenshot, we can directly change the Swift version in Build Settings. But after changing swift version you might see many errors in your project because of the syntax changes among the different Swift versions. If you are intended to upgrade your Swift version then you can use the automatic tool in Xcode. For that please perform the following action.

Edit -> Convert -> To Current Swift Syntax

upgrade swift version

That’s it, this is how to check & change the swift version in Xcode. In case of syntax errors, to get further help you can read the official documentation for the Swift version you are intending to upgrade.

If you have any questions feel free to ask in the comments section below.

Next

Get Current Location in Swift IOS

Please share this post:
Native Mobile Application Developer (Android + IOS) having experience in Java, Swift, Kotlin, Objective C, Unity, C#, C/C++, NODE JS & PHP.

One thought on “How to Check & Change Swift Version in Xcode

Ask a Question

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

%d bloggers like this: