在 Terminal 裡面玩 Swift
目錄
根據 Xcode 6 beta 發布的訊息, Swift 也有和其他語言一樣可以在 terminal 開啟 REPL 工具可以用。
Command Line
Xcode’s debugger includes an interactive version of the Swift language, known as the REPL (Read-Eval-Print-Loop). Use Swift syntax to evaluate and interact with your running app or write new code in a script-like environment. The REPL is available from within LLDB in Xcode’s console, or from Terminal.
怎麼開
1 | sudo xcode-select -s /Applications/Xcode6-Beta.app/Contents/Developer/ |
那在 Xcode6-Beta.app
的地方,可以根據 Beta 版本不同改成對應的加上 2 或現在的 3 。
執行結束後,接著輸入
1 | xcrun swift |
enter 之後會 就會 prompt 訊息出來,就可以開始用了:
1 | Welcome to Swift! Type :help for assistance. |
Have fun!