Swiftをコマンドラインから実行してみる
Swiftをコマンドラインから実行する
Xcode6のβ版もインストールしまして、コマンドラインからやってみるかと。
まあこちら記事のコメントと、stackoverflowの記事にある通り、
ios - How can I use swift in Terminal? - Stack Overflow
$ sudo xcode-select -switch /Applications/Xcode6-Beta.app/Contents/Developer/
したんですけど、なんかこんなのが
Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.
まずライセンスに同意しなきゃならんと。ちょっと面食らいましたけど、こちらの記事を参考に
Agreeing to the Xcode/iOS license... のエラーがでた時の対処法 - Qiita
sudo xcrun cc
すると
$ sudo xcrun cc You have not agreed to the Xcode license agreements. You must agree to both license agreements below in order to use Xcode. Hit the Enter key to view the license agreements at '/Applications/Xcode6-Beta.app/Contents/Resources/English.lproj/License.rtf'
とでてくるのでEnterを押すと、いろいろ英語で出てきますので、スペースを押して画面を進めていく。
そして最後に
By typing 'agree' you are agreeing to the terms of the software license agreements. Type 'print' to print them or anything else to cancel, [agree, print, cancel]
という文章が出てきますので、agree
とタイプする。
その後、$ xcrun swift
と打つと
Welcome to Swift! Type :help for assistance. 1>
こんな感じでウェルカムされますんで、swiftライフを始めることができますよ、と。
とりあえずお決まりのこれで
1> println("Hello, world") Hello, world
ヘルプは:help
:quit
で終了します。(Ctrl + D)でもおk。
(7/9追記)
Xcode Beta3に更新
まあアップルのサイトからDLして、古いものは一応App Cleaner2を使ってリムーブ。
その際にいろいろ関連ファイルも表示されたが、あくまで古いXcode Beta本体だけを消去。
パスの一部をXcode-Beta3.app
にして
$ sudo xcode-select -switch /Applications/Xcode6-Beta3.app/Contents/Developer/
$ xcrun swift
Sublime Text2でもSwiftを実行できるようにしていたが
Sublime Text2上でSwiftをコンパイル&実行 - ハイパーニートプログラマーへの道
パスを修正
{ /*"cmd": ["swift $file_name && swift -i $file_name"],*/ "cmd": ["swift -i $file_name"], "file_regex": "^(...*?):([0-9]*):?([0-9]*)", "path": "/Applications/Xcode6-Beta3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/", "selector": "source.swift", "shell": true }