How can I use swift in Terminal? How can I use swift in Terminal? xcode xcode

How can I use swift in Terminal?


sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

then you can do one of these:

xcrun swift lldb --repl

As of Xcode 6.1 - typing swift in the terminal launches the REPL as well.


Alternatively, if you don't want to mess up your current dev environment, you can just run:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift


Step 1: Open Terminal
Step 2: Type "swift"
Step 3: There's no step 3

Example:

GoldCoast:~ macmark$ swiftWelcome to Swift!  Type :help for assistance.  1> println("Hello, world")Hello, world  2> var myVariable = 42myVariable: Int = 42  3> myVariable = 50  4> let myConstant = 42myConstant: Int = 42  5> println(myVariable)50  6> let label = "The width is "label: String = "The width is "  7> let width = 94width: Int = 94  8> let widthLabel = label + String(width)widthLabel: String = "The width is 94"  9> :exitGoldCoast:~ macmark$