> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/ios/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/ios/appendix/tips/reportswiftversion.md).

# Swift version

{% tabs %}
{% tab title="💾 程式" %}

```swift
// 回報 Swift 版本
public func swiftVersion() -> String {
    
    #if swift(>=5.5)
    return ("Swift 5.5")
    
    #elseif swift(>=5.4)
    return ("Swift 5.4")
    
    #elseif swift(>=5.3)
    return ("Swift 5.3")
    
    #elseif swift(>=5.2)
    return ("Swift 5.2")
    
    #elseif swift(>=5.1)
    return ("Swift 5.1")
    
    #elseif swift(>=5.0)
    return ("Swift 5.0")
    
    
    #elseif swift(>=4.2)
    return ("Swift 4.2")
    
    #elseif swift(>=4.1)
    return ("Swift 4.1")
    
    #elseif swift(>=4.0)
    return ("Swift 4.0")
    
    #else
    return ("How OLD are you?")
    
    #endif
}
```

another example:

```swift
#if swift(>=4.2)
print("Swift 4.2")
#elseif swift(>=4.1)
print("Swift 4.1")
#elseif swift(>=4.0)
...
#endif
```

{% endtab %}

{% tab title="📗 參考" %}

* [ ] James Dempsey ⟩ [Swift Version](https://swiftversion.net/?utm_campaign=iOS%2BDev%2BWeekly\&utm_medium=email\&utm_source=iOS%2BDev%2BWeekly%2BIssue%2B485)
* [ ] [How to Check & Change Swift Version in Xcode](https://handyopinion.com/how-to-check-change-swift-version-in-xcode/)
* [ ] [Quickly displaying the Swift version that ships with Xcode](https://www.jessesquires.com/blog/2022/03/04/quickly-displaying-the-swift-version-that-ships-with-xcode/)
  {% endtab %}

{% tab title="🗣 討論" %}

* [Get Swift version information programmatically](https://forums.swift.org/t/get-swift-version-information-programmatically/11813)
* [How Do I See Which Version of Swift I'm Using?](https://stackoverflow.com/a/46080904/5409815)
* [How to print out Swift's version in a program?](https://stackoverflow.com/questions/32312485/how-to-print-out-swifts-version-in-a-program)
  {% endtab %}
  {% endtabs %}
