SwiftVersionDetector allows you to detect Swift version at runtime.

Note that detecting the Swift version of the machine on which your app is being executed is extremely different from Swift conditional compilation which allows to get Swift version only at compile-time.


let version = try SwiftVersionDetector.detectRuntimeSwiftVersion()
print(version.major) // Prints "5"
print(version.minor) // Prints "3"
print(version) // Prints "Swift version 5.3"


Xcode Projects

Select File -> Add Packages... -> search for https://github.com/Ventus218/SwiftVersionDetector -> Add Package -> Add Package

Swift Package Manager Projects

You can add SwiftVersionDetector as a package dependency in your Package.swift file:

Remember to check for an updated version 🙂

let package = Package(
    dependencies: [
        .package(url: "https://github.com/Ventus218/SwiftVersionDetector", from: "1.0.0"),

From there, refer to the SwiftVersionDetector “product” delivered by the SwiftVersionDetector “package” inside of any of your project’s target dependencies:

targets: [
        name: "YourAppName",
        dependencies: [
                name: "SwiftVersionDetector",
                package: "SwiftVersionDetector"

Then simply import SwiftVersionDetector wherever you’d like to use it.


Contributions to SwiftVersionDetector are most welcome. Check out some of the issue templates for more info.


SwiftVersionDetector is available under the MIT license. See the LICENSE file for more info.


View Github