How to compile with Xcode and Swift 2.2

Tonight, I decided to kick the wheels of Swift 2.2 from inside Xcode. I knew it was possible but it took me a while to figure out the exact directions as I was thinking I needed to updated the compiler in the build phases, not launch Xcode with a different toolchain. Turned out I should just have read the instructions better.

Here are the steps:

Install Swift 2.2 First install Swift 2.2, following the directions from When I checked a few minutes ago, the links were down so you may have to wait until tomorrow. There’s a pkg installer and the setup process is simple. Make sure you quite out of Xcode first.

I had to adjust the initial instructions slightly as I run tcsh and not bash (I know, I know). I have my 2.2 Swift set up as a symbolic link for ease-of-reference.

lrwxr-xr-x 1 ericasadun staff 68 Dec 3 09:19 swift22@ -> /Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin/swift

Test Swift 2.2 Execute Swift to make sure the proper version is installed (you’ll see this in the first line) and then quit out.

% swift22
Welcome to Apple Swift version 2.2-dev (LLVM 46be9ff861, Clang 4deb154edc, Swift 778f82939c). Type :help for assistance.

Launch Xcode From the command-line, with Xcode closed, use xcrun launch-with-toolchain to select the toolchain you wish to rely on.

% xcrun launch-with-toolchain /Library/Developer/Toolchains/swift-latest.xctoolchain/
Verifying toolchain code signature...

Verified signature.

Launching Xcode...

2015-12-03 18:28:26.354 Xcode[9728:2177144] Build settings from command line:
2015-12-03 18:28:26.354 Xcode[9728:2177144] ENABLE_BITCODE = NO
2015-12-03 18:28:26.354 Xcode[9728:2177144] SWIFT_DISABLE_REQUIRED_ARCLITE = YES
2015-12-03 18:28:26.354 Xcode[9728:2177144] SWIFT_EXEC = /Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin/swiftc
2015-12-03 18:28:26.354 Xcode[9728:2177144] SWIFT_LINK_OBJC_RUNTIME = YES
2015-12-03 18:28:26.354 Xcode[9728:2177144] XCODE_DEFAULT_TOOLCHAIN_OVERRIDE = /Library/Developer/Toolchains/swift-latest.xctoolchain (etc)

Have fun. Although the revised Swift Programming Language states in its Document Revision History that several features have been removed from discussions, I was still able to compile with them. I tested variable function arguments, ++ incrementors, and currying. I assume these will be removed later.

Updated for Swift 2.2.
Removed discussion of var patterns, variable function arguments, and the special syntax for curried functions.

Skip playgrounds. You cannot use the 2.2 toolchain for playgrounds. (“The toolchain currently being used for debugging is not compatible with playgrounds. Relaunch Xcode with the default toolchain to use playgrounds)

Screen Shot 2015-12-03 at 6.42.27 PM

To conclude: I’ve put a standard library dump here. This includes both module declarations and 2.1/2.2 diffs.

One Comment

  • I had to use sudo xcrun /Applications/ /Library/Developer/Toolchains/swift-latest.xctoolchain</code?