swiftxcodeterminal

How do I see which version of Swift I'm using?


I just created a new Swift project within Xcode. I am wondering which version of Swift it's using.

How can I see, in Xcode or the terminal, what version of Swift I am using inside my project?


Solution

  • Project build settings have a block 'Swift Compiler - Languages', which stores information about Swift Language Version in key-value format. It will show you all available (supported) Swift Language Version for your Xcode and active version also by a tick mark.

    Project ► (Select Your Project Target) ► Build Settings ► (Type 'swift_version' in the Search bar) Swift Compiler Language ► Swift Language Version ► Click on Language list to open it (and there will be a tick mark on any one of list-item, that will be current swift version).

    Look at this snapshot, for easy understanding:

    xcode with described areas highlighted


    With help of following code, programmatically you can find Swift version supported by your project.

    #if swift(>=5.10)
    print("Hello, Swift 5.10")
    
    #elseif swift(>=5.9)
    print("Hello, Swift 5.9")
    
    #elseif swift(>=5.8)
    print("Hello, Swift 5.8")
    
    #elseif swift(>=5.7)
    print("Hello, Swift 5.7")
    
    #elseif swift(>=5.6)
    print("Hello, Swift 5.6")
    
    #elseif swift(>=5.5)
    print("Hello, Swift 5.5")
    
    #elseif swift(>=5.4)
    print("Hello, Swift 5.4")
    
    #elseif swift(>=5.3)
    print("Hello, Swift 5.3")
    
    #elseif 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")
    
    #elseif swift(>=3.2)
    print("Hello, Swift 3.2")
    
    #elseif swift(>=3.0)
    print("Hello, Swift 3.0")
    
    #elseif swift(>=2.2)
    print("Hello, Swift 2.2")
    
    #elseif swift(>=2.1)
    print("Hello, Swift 2.1")
    
    #elseif swift(>=2.0)
    print("Hello, Swift 2.0")
    
    #elseif swift(>=1.2)
    print("Hello, Swift 1.2")
    
    #elseif swift(>=1.1)
    print("Hello, Swift 1.1")
    
    #elseif swift(>=1.0)
    print("Hello, Swift 1.0")
    
    #endif
    

    Here is result using Playground (with Xcode 11.x)

    PLEASE NOTE:
    Building your code as Swift 4 in Xcode doesn't actually switch to a Swift 4 compiler, it just tells the compiler to try to apply the same language rules that the Swift 4 compiler would have used.

    enter image description here