Charlie Charlie - 3 months ago 26
Swift Question

XCode set to use Swift 2.0 by default?

This could be a seriously dumb question, but I have checked in the terminal that my computer is using swift 1.2 right now:

$ xcrun swift -version
Apple Swift version 1.2 (swiftlang-602.0.53.1 clang-602.0.53)
Target: x86_64-apple-darwin14.4.0


I want to make sure I'm using swift 2.0 in my new projects so I am learning to use things like "guard" and whatnot.

I know I can Edit -> Convert -> To lastest Swift syntax on existing code I've written, but I am wondering can you set xcode to just use swift 2.0 by default on new projects?

I find myself getting confused if my code is written incorrectly or if I am simply trying to write swift 2.0 in a swift 1.2 project. I also don't understand, is doing the edit -> convert on each file the correct way to do this?! What if I have a huge project with 100 files!?

Thanks!

Answer

The release version of Xcode (6.4) only supports Swift 1.2. You need to get the latest beta of Xcode 7 (beta 6). Once you have installed that (and you use it instead of the 6.x version) it will automatically use Swift 2.0.

You may also need to run xcode-select from the command line to switch the command line tools to use Swift 2.

xcode-select --switch /path/to/Xcode7/beta

You might need to run it with sudo