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.
Asked
Active
Viewed 5,436 times
16
-
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 Answers
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
-
Thank you. I assume to switch this back to the regular Xcode CLI, I just do `sudo xcode-select -s /Applications/Xcode.app/Contents/Developer/` ? – Enrico Susatyo Jun 03 '14 at 23:47
-
1Yes, this selects which xcrun, xcodebuild, cc and other command line compile tools location – Vinicius Miana Jun 03 '14 at 23:50
-
-
5
-
-
Xcode 6.0.1, this doesn't appear to be supported for MacOX10.9? Got "
:0: error: the SDK 'MacOSX10.9.sdk' does not support Swift" – kawingkelvin Sep 24 '14 at 16:24 -
After the an update in XCode, you may need to run xcode-select again. With XCode 6, there is a new trick. See my edited answer – Vinicius Miana Sep 25 '14 at 11:43
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