22

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!

6
  • 3
    Don't upgrade Xcode if you don't want to upgrade Swift. Commented Mar 25, 2016 at 2:23
  • 1
    @rmaddy Are there no other ways? Commented Mar 25, 2016 at 2:25
  • 1
    If you're building an app for the app store, your only choices are to use Xcode 7.2 or to update your code to Swift 2.2. Commented Mar 25, 2016 at 2:28
  • 4
    Note that you can have multiple versions of Xcode installed, so you can use Xcode 7.2 on existing projects and use Xcode 7.3 on new projects if you need to. Commented Mar 25, 2016 at 2:29
  • 4
    You can download older versions of Xcode here if you need to. Commented Mar 25, 2016 at 2:30

4 Answers 4

19

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

Sign up to request clarification or add additional context in comments.

Thanks for that. in Xcode 9-Beta though, I am getting <unknown>: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 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?
@GuyDaher I believe that Xcode 8.3 fix it. Try to clean your build, clean pod and run ´pod install´ again
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.

These scripts are really handy for managing multiple versions of Xcode alongside one another: github.com/neonichu/xcode-install Personally I'd never leave it down to the Mac App Store to manage your Xcode for you.
Oh my god I had no idea it was this bad
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

Comments

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

This switches the version and not the compiler.

Your Answer

Draft saved
Draft discarded

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.