5

Can I run Swift 3 from the command line after installing the Xcode 8 beta? I see that /usr/bin/swift is still the May 5th Swift 2.2. I was hoping to see something like /usr/bin/swift3 but no such luck.

swift.org downloads says that "Swift 3.0 Preview 1 is available as part of Xcode 8.0 beta." But I haven't found instructions on running a command line Swift 3 using the Xcode 8 beta.

Ideally, I would like to use the interactive REPL ... as well as do command-line compilation of Swift Package Manager code.

Rick Majpruz
  • 641
  • 3
  • 16
  • SPM is not yet integrated into Xcode 8. – Eric Aya Jun 26 '16 at 11:36
  • Xcode does need proper SPM integration. However, using [Arsen's](http://stackoverflow.com/users/5328417/arsen) tip on changing "Command line tools", I was able to compile an SPM that using "swift build" from the command line. And I **did** use Swift 3 code such as: `chars.index(chars.startIndex, offsetBy: 3)` – Rick Majpruz Jun 26 '16 at 11:58
  • Yes, I'm using Swift 3 for CLI apps too, it works well. :) I was just commenting on the last part of the last sentence of your question, which seemed related to Xcode 8 too. – Eric Aya Jun 26 '16 at 12:12
  • I just noticed that my questions is the same as [Where are the swift/swiftc binaries for v3?](http://stackoverflow.com/questions/37889790/where-are-the-swift-swiftc-binaries-for-v3) As [Maciek](http://stackoverflow.com/users/1041469/maciek-czarnik) and [Arsen](http://stackoverflow.com/users/5328417/arsen) imply in their answers, the Swift binary is the same for Swift 2.2 and for Swift 3, namely /usr/bin/swift. But `xcode select -s ...` switches the underlying Xcode install that gets used. – Rick Majpruz Jun 28 '16 at 15:33
  • I just marked [Maciek's](http://stackoverflow.com/users/1041469/maciek-czarnik) answer as correct. But [Arsen's](http://stackoverflow.com/users/5328417/arsen) answer is correct and very handy as an easy GUI interaction. Overall though, `xcode-select` allow for scripting which is essential for automated testing of a code base that alternates between Swift 2.2 and Swift 3 code. Both answers should be marked as useful but my reputation is still too low. – Rick Majpruz Jun 28 '16 at 15:43

2 Answers2

10
sudo xcode-select -s /Applications/Xcode-beta.app 
swift
Maciek Czarnik
  • 5,950
  • 2
  • 37
  • 50
  • Good for scripting. But I have to use `sudo xcode-select -s ~/Applications/Xcode-beta.app` because I placed my beta in ~/Applications. – Rick Majpruz Jun 27 '16 at 19:17
  • Glad I could have helped you @RickMajpruz , feel free to upvote my answer. Thanks! – Maciek Czarnik Jun 27 '16 at 19:30
  • Now I won't have to look up this answer anymore: `alias sw3="sudo xcode-select -s ~/Applications/Xcode-beta.app ; swift"` Then toggle back with: `alias sw2="sudo xcode-select -s /Applications/Xcode.app ; swift"` – Rick Majpruz Jul 01 '16 at 16:44
6

Run Xcode-Beta and change Command line tools

enter image description here

Profit:

enter image description here

Arsen
  • 10,815
  • 2
  • 34
  • 46
  • I see that the timestamp on the 18K /usr/bin/swift remained at May 5. So the /usr/bin/swift binary must inspect the Xcode apps (both Mac Store install as well as this beta) to pick the proper REPL and compiler. – Rick Majpruz Jun 26 '16 at 11:44