20

I'm using Xcode 7.3 but my project is in Swift 2.1. I don't want to update my codes right now. So how can I choose or download older version of Swift compiler? Many thanks in advance!

Lumialxk
  • 6,239
  • 6
  • 24
  • 47

4 Answers4

18

The following example is tested on Xcode 8.3 with swift 3.1

If you are using Xcode 8 you can download toolchains with needed Swift versions

1) Open this link: https://swift.org/download/#releases

2) Download Toolchain with swift version that you need. For example I have 3.1 version of swift and downloaded swift 3.0.2

enter image description here

3) Open .pkg file and install it.

enter image description here

4) Open Xcode and select in menu:

Xcode -> Toolchains -> Select Swift Version you need.

That is all folks

enter image description here

Nikolay Shubenkov
  • 3,133
  • 1
  • 29
  • 31
  • 3
    Thanks for that. in Xcode 9-Beta though, I am getting `:0: error: unknown argument: '-index-store-path' Command /Library/Developer/Toolchains/swift-3.1.1-RELEASE.xctoolchain/usr/bin/swiftc failed with exit code 1`. Any idea why? – Guy Daher Jun 12 '17 at 10:03
  • @Guy Daher Could you provider more information when did you get this error? do you have cocoapods or other dependencies in your project? maybe this can help? – Nikolay Shubenkov Jun 13 '17 at 07:20
  • 1
    @GuyDaher I believe that Xcode 8.3 fix it. Try to clean your build, clean pod and run ´pod install´ again – Francis Rodrigues Jul 26 '18 at 14:28
11

Originally I posted this is a comment, but I should have just posted it as an answer:

If you're writing an app for the App Store, you can only use a release (non-beta) version of Xcode (see “Submitting Apps to the App Store using Xcode”) and the toolchain supplied with that version of Xcode (see “Using Downloads / Apple Platforms”). So you can either use Xcode 7.2 and continue using Swift 2.1, or you can use Xcode 7.3 and update your code to Swift 2.2.

You can have multiple versions of Xcode installed. You can keep Xcode 7.2 installed and use it for your non-updated Swift 2.1 projects, and use Xcode 7.3 on new projects. Note that you'll have to manually open each project in the appropriate version of Xcode. You can download old versions of Xcode here.

If you're not going to put your app in the App Store, then maybe you could extract the Swift 2.1 toolchain from the Xcode 7.2 bundle and turn it into a .xctoolchain for use with Xcode 7.3, but you're really in unexplored, unsupported territory if you go that route.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • These scripts are really handy for managing multiple versions of Xcode alongside one another: https://github.com/neonichu/xcode-install Personally I'd never leave it down to the Mac App Store to manage your Xcode for you. – Andrew Ebling May 25 '16 at 13:47
  • Oh my god I had no idea it was this bad – Script Kitty Oct 14 '17 at 04:18
4

If you're following the answers involving a .xctoolchain combined with Xcode 9 beta you'll encounter an error similar to this: <unknown>:0: error: unknown argument: '-index-store-path' Command /Library/Developer/Toolchains/swift-3.1.1-RELEASE.xctoolchai‌​n/usr/bin/swiftc failed with exit code 1

The reason is that Apple has added a new feature/argument, which hasn't made its way to open source Swift yet. You can get around this issue by launching Xcode from the command line with the feature disabled like this: /path/to/Xcode-beta.app/Contents/MacOS/Xcode -IDEIndexEnableBoltIndex NO

Thanks to the Swift team

allenh
  • 6,582
  • 2
  • 24
  • 40
3

Xcode 9 - Xcode 10

Select your target, then in your Build Settings, search for "swift language" and then you will find Swift Language Version.

enter image description here

Community
  • 1
  • 1
Guy Daher
  • 5,526
  • 5
  • 42
  • 67