16

I would like to know how to do this from the CLI so that I can test out some codes without launching Xcode. I saw someone did this but I couldn't find a way to do this yet.

Enrico Susatyo
  • 19,372
  • 18
  • 95
  • 156
  • None of this is necessary anymore. All you have to do now is open your terminal and type swift and hit enter. – jungledev Mar 22 '16 at 18:10

2 Answers2

37

After installing the Xcode6 beta, do

$ sudo xcode-select -s /Applications/Xcode6-Beta.app/Contents/Developer/

$ xcrun swift

is a Swift REPL

EDITED:

For XCode 6, use:

xcrun swift -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk
Vinicius Miana
  • 2,047
  • 17
  • 27
16

To extend on @vinicius answer, you can also use it without changing your default Xcode by using:

DEVELOPER_DIR=/Applications/Xcode6-Beta.app/Contents/Developer/ xcrun swift

The easiest way to do that will be to edit your .bashrc and append:

alias swift='DEVELOPER_DIR=/Applications/Xcode6-Beta.app/Contents/Developer/ xcrun swift'

At that point you'll be able to run it just by typing swift

If you use a csh variant you'll need:

env DEVELOPER_DIR=/Applications/Xcode6-Beta.app/Contents/Developer/ xcrun swift

and create the alias with

alias swift 'env DEVELOPER_DIR=/Applications/Xcode6-Beta.app/Contents/Developer/ xcrun swift'
David Berry
  • 40,941
  • 12
  • 84
  • 95