NOTE: From Xcode 8 to Xcode 8.2.x you can use swift 2.3 even though Xcode 8 uses swift 3.x as default swift version. To use swift 2.3, just turn on flag Use Legacy Swift Language Version to YES from Build Setting and XCode will use Swift 2.3 for that project target.
#!/bin/bash
swiftversion=$(node SwiftVerSlicer.js "${xcrun swift -version}");
echo $swiftversion
SwiftVerSlicer.js:
// begin script
const inputString = `${process.argv[2]}`
let searchTerm = (inputString.indexOf('(') - 1)//-1 cause whitespace
let version = inputString.slice(0,searchTerm)
console.log(version)
// end script
Xcode 13.4.1 : Swift version 5.6.1
Xcode 13.2 : Swift version 5.5.2
Xcode 12.5 : Swift version 5.4.2
Xcode 12.3 : Swift version 5.3.2
Xcode 12.2 : Swift version 5.3.1
Xcode 11.6 : Swift version 5.2.4
Xcode 11.5 : Swift version 5.2.4
Xcode 11.4 : Swift version 5.2
Xcode 11.3 : Swift version 5.1.3
Xcode 11.2.1 : Swift version 5.1.2
Xcode 11.1 : Swift version 5.1
Xcode 13.4.1 : Swift version 5.6.1
Xcode 13.3 : Swift version 5.6
Xcode 13.2 : Swift version 5.5.2
Xcode 12.5 : Swift version 5.4.2
Xcode 12.3 : Swift version 5.3.2
Xcode 12.2 : Swift version 5.3.1
Xcode 11.6 : Swift version 5.2.4
Xcode 11.5 : Swift version 5.2.4
Xcode 11.4 : Swift version 5.2
Xcode 11.3 : Swift version 5.1.3
Xcode 11.2.1 : Swift version 5.1.2
Xcode 11.1 : Swift version 5.1